tags:

views:

47

answers:

2

My plan is to load a picture from a users hard drive and then do some wizardry on it in memory.

First thing is first, how can I get the height and width from an Image?

Also, say I wanted to select a rectangular piece from the image, how would I do that in memory (no GUI)?

Thank you for your guidance.

+1  A: 

You will need to add a refernce to the System.Drawing namespace.

using( Image image = Image.FromFile( path ) );
{
    // use image.Width and image.Height
}

You can then use the Clone method with a Rectangle as the argument to get a sub-section of the image, or you can just loop through the pixels in the Rectangle of interest (you'll want to use the Bitmap class for that, maybe LockBits and a pointer depending on how large the image is and how fast this needs to be).

Ed Swangren
A: 

What are you using? Outside WPF, you can use System.Drawing.Bitmap class Width and Height properties to get the size of an image. Clone method will enable you to copy a rectangular piece.

You can also use image classes used in GUI applications outside WPF/Windows Forms application.

MainMa
I guess the OP is referring to an env other than WPF, since he would probably tag it then 'wpf'
Shimmy
That's why my answer is more complete about doing it without WPF, with just System.Drawing.Bitmap. I mention WPF just to highlight that WPF methods can also be used in a non-GUI application.
MainMa