0

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?

user1763295
  • 860
  • 3
  • 16
  • 34
  • In your example the image has no idea which portion of it was drawn to the graphics context. You'll need to intercept the `FillRectangle` call. – Artfunkel Apr 22 '14 at 17:01

1 Answers1

3

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

Community
  • 1
  • 1
psamwel
  • 1,042
  • 9
  • 15