So I'm writing a text on an image with DrawString in a rectangle. My text is written on multiple line in my rectangle. How can I get the pixel position of the last character drawn on my image ? Because this character can be at any Width because of the multiple line. I think it's more easy understand with an image, so I want to get the pixel position here, at the "?":
I tried everything, searched for hours, MeasureString, even OCR, but I didn't find any way to get the pixel position of the last character of the drawn text.
I need this position because I want to append it an image with DrawImage.
Related
I have an app that prints very small labels.
One thing I have noticed is that the printing (using DrawString with a rectangle) aligns text based on the TOP of the font ascender size. So when there are 2 font sizes on a line, you get this.
The PrintDocument object apparently has no ability to do line spacing or vertical alignment.
In other words I guess I need to calculate all that myself.
My main question is:
Is there another object I should be using where I can align text on the baseline, and "tighten" the vertical spacing to prevent my content from overrunning the labels? You know, like Word and LibreOffice?
Or do I have to reverse engineer it all in my code.
I'm able to fill a rectangle with an image and i apply a mask on top of the image using this code
args.DrawingSession.FillRectangle(rect, imgRnd, mask);
i need to apply some transform to this image, i'am able to do that with no issue, but i have encounter a strange issue, the last pixel is repeated.
i have used
imgRnd.ExtendX = CanvasEdgeBehavior.Wrap;
imgRnd.ExtendY = CanvasEdgeBehavior.Wrap;
and the image is repeated continuously.
My question is : there is a way to draw one time the image disabling and ExtendX and ExtendY?
FillRectangle will always fill all the pixels within the specified rectangle. The edge behavior enum controls what value they are filled with if the image is positioned such that it does not completely cover the rectangle being drawn.
How exactly are you transforming the image? Can you change that to also transform the rectangle itself, so you won't be trying to fill pixels that aren't covered by the image?
Another option is to use image effects (Microsoft.Graphics.Canvas.Effects namespace) which give much more detailed control than FillRectangle over how multiple images are transformed, combined, etc.
I have a .png image, i want to get the points that the shape is made of.
Example:
I know that i won't get a perfect output but anything would be good..
How should I start?
I would need to get a list of points out of my image.
Very simple. Replace an NON white pixels by black. Then loop in each black pixel and turn them white if not adjacent to at least 1 white pixel.
I have to extract the red mark graph using Aforge blob extraction method but I am unable to extract that particular grid in order to read it.
This task may be pretty simply solved without further AForge using.
If all grids in your sample have a similar structure: i.e. homogeneous grid with vertical-horizonal graphic of function, you can use following algorithm:
Calculating white pixel density for vertical direction as you can see at image below. It's just a normalized value of sum of all RGB components in each horizontal line (Dont know what's name of it. If anybody knows it, please report).
You must extract y-axis values with lowest white pixel density and ignore y-axis values in green ellipses. If this minimums has not been founded, you must consider values in green ellipses too. If in considered y-axis values there are white pixels at right in image too many, just ignore it. Otherwise, congrats! We found segment of black line until right angle.
After that this process must be repeated for next horizontal line detection until end of image.
Construction of final function from founded horizontal lines.
If you want to just retain the graph in the grid and remove all other lines or line segments and if your image is a sample of all the images that you are planning to process, then I see two options to try out:
1) If there is a difference in greyscale threshold of area which is not having graph line to that of graph line, then use that and apply one of the Thresholding APIs of Aforge.Net, like IterativeThreshold.
2) You may try errosion API of AForge.Net and iterate that for N times, until all other lines are eroded except the graph line. If graph line becomes lighter due to erossion, apply Dillation on top of it.
I am custom drawing a text box and now I am implementing the part where the user can click on a line and have the cursor move to where he clicked.
I know how to get the row of text he clicked on because the character height is constant across all fonts, but not the column, because I'm not sure how to say "get me all the text that can be drawn before this amount of pixels," and because character width is not consistent unless you're using a fixed-width font, which is not a guarantee.
So I have the point from which I'm drawing the string (0) then I have the point that the user clicked. How do I get the string index of the character they clicked on?
Extra info: I am drawing the text by storing the lines in a List then iterating the list and using Graphics.DrawString on each line.
There is no simple method to find the character at a pixel.
However you can find the pixels that a string will fill. Use the Graphics.MeasureCharacterRanges method. You can perform a binary search on your string until you find the string where MeasureCharacterRanges returns your cursor position.
Note: You might see the Graphics.MeasureString method and be tempted to use that. DON'T! That method doesn't return accurate measurements. I can't remember why, but you will do your head in if you try!