Copying a portion of a Bitmap

robodale

New member
Joined
Sep 20, 2003
Messages
3
Location
A house by another house which is by another house
I am having trouble trying to copy a portion of a previously created Bitmap image I have created. Basically what I am trying to do is pass in a Bitmap image I have created into a method which then saves a 100 x 100 portion of the original image into a new Bitmap object. I then save both the original and new image so I can see what the result is. My code that doesnt work follows:

public void ProcessGraphics(Bitmap bitmapORIG)
{
System.Drawing.Image image;
Bitmap bitmapNEW;

image = (Image) bitmapORIG;
bitmapNEW = new Bitmap(image, 100, 100);

image.Save(@"C:\temp\Image_Original.gif", System.Drawing.Imaging.ImageFormat.Gif);
bitmapNEW.Save(@"C:\temp\Image_New.gif", System.Drawing.Imaging.ImageFormat.Gif);

}

The only thing that my coding above does is resize (rescale?) the original image into a smaller image. This is not what I want - I merely want a 100 x 100 part of the original image, in its original scale.

Anybody know how I should attack this?
many thanks.
 
Last edited by a moderator:
Copying a portion of a Bitmap....EASY SOLUTION!

Wow, I am an idiot. I scoured the .NET help and found out how to do this:


public void ProcessGraphics(Bitmap bitmapORIG)
{
Rectangle rectangle;
Bitmap bitmapNEW;

rectangle = new Rectangle(0, 0, 100, 100); // test dims
bitmapNEW = bitmapORIG.Clone(rectangle, System.Drawing.Imaging.PixelFormat.DontCare);

bitmapORIG.Save(@"C:\temp\Report_NOT_clipped.gif", System.Drawing.Imaging.ImageFormat.Gif);
bitmapNEW.Save(@"C:\temp\Report_clipped.gif", System.Drawing.Imaging.ImageFormat.Gif);
}

thanks anyway, you all!
 
For this:

System.Drawing.Imaging.PixelFormat.DontCare

You should really use

bitmapORIG.pixelformat




Dan
 
Back
Top