How to remove outer white space around an image in c#? - c#

I am new to c# and wanted to develop an app which can remove outer white space of image, image is surrounded with black border so it can easily be cropped and removed outer white space.
I am attaching to two image before and after cropping, as you can see Image 2 is cropped and outer white space is removed, furthermore, its rotation is also adjusted to make image proper in rectangle format. Finally, the size of image is 800x1200 pixels from 1946x2817
Image before cropping [1946x2817] with outer space and border
Image after cropped [800x1200] without outer space and border

Related

Get the last character pixel position drawn with DrawString in C#?

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.

Win2D draw single image

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.

Increase Size of Black Bullets in Image in C#

Given the following image:
I need to output this image:
I want to increase the size of Black Pixels in the image using C# or AForge.Net
The image processing operation you need is morphological dilation or, in your case with black dots on white background morphological erosion.

C# converting png image to list of points

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.

How can I set an image to have a transparent background in C# without using Bitmap.MakeTransparent()?

I want to set an image to have a transparent background, but I do not want to replace all pixels of a specific colour with transparency.
To be more specific, the image is a thumbnail image for a folder, obtained via IShellItemImageFactory.GetImage. This gives me a Bitmap, as displayed in Windows Explorer thumbnail view, but the background is solid white.
I can use Bitmap.MakeTransparent on it, and that will work in most cases, but in any cases where the thumbnail image contains white itself (for example, a folder that contains images, which include white colours).
Incidently, this is the first time in over 10 years as a developer that, after googling my question, I have not found an answer anywhere, and I've actually had to ask it myself. (I think that means I just levelled up! Yippee, I am now a level 2 developer...)
Use flood-fill algorithm to fill pixels of the same color from the OUTSIDE as you need it. It is something similar to magic wand in photoshop.
http://en.wikipedia.org/wiki/Flood_fill
What I would do is flood-fill with some obscure color (Magenta always does it for me), then replace that color with transparent (I don't know if flood filling with transparent pixels is feasible).
So what you're getting from IShellItemImageFactory.GetImage is a composite image that contains the original image on a white background? I suspect the white background is there if the image doesn't have the same aspect ratio as the thumbnail size. For example, if you ask for a 96x96 thumbnail of a 640x480 image, there's going to be some white space at top and bottom.
If that's the case, you have a problem. You can't differentiate between white pixels that are contained in the image, and white pixels that are added by GetImage.
There are a few things you could do. You could load the image and resize it yourself. That's probably the easiest. You'd want to maintain your own thumbnail cache then.
Or you could examine the image returned by GetImage to look for white space on the sides. Basically, if every pixel on a row (or column) is white, then make that row (or column) transparent. It's a little more complicated than that (the NBA logo, for example). But that's essentially what you'd want to do.

Categories