user1763295
user1763295

Reputation: 1088

Get actual Image size

How do I get the USED size of an image. For example:

Image image = new Bitmap(400, 400);
using (Graphics g = Graphics.FromImage(image))
{
   g.FillRectangle(Brushes.Black, new Rectangle(100, 100, 200, 200));
}

The image is 400x400 but the used area is 200x200. Is there a way I can get the dimensions of the used area of the image?

Upvotes: 0

Views: 82

Answers (1)

psamwel
psamwel

Reputation: 1062

There is nothing out of the box that I'm aware of to do this within the GDI+ libraries. You could however utilize the concept of whitespace cropping to determine the top/bottom/left/right line of the image that has either perfect whitespace or near ("close" to RGB 255,255,255), and then derive your "used" rectangle from there.

See the following for more details. Remove surrounding whitespace from an image

Upvotes: 3

Related Questions