PDA

Click to See Complete Forum and Search --> : Converting to 32bpp Bitmap


penagate
Jan 10th, 2007, 12:21 PM
As a side project and something to help me learn about graphics in .NET I decided to make a simple image filter.

I have one problem, which is loading the image into a 32bpp bitmap which I can then manipulate. After drawing into the copied bitmap the image is stretched to about the top 3/4, in the correct dimensions.

I've been trying to pinpoint the problem without success, so I was wondering if anyone could take a look. It's in C# 2.0.

Thanks
- P

eakin
Jan 11th, 2007, 02:59 PM
I could be wrong

but I was experiencing a problem where I was cropping part of an image and saving the cropped part as a new bitmap. My problem was that the cropped part only took up around 1/4 of the new bitmap and the rest was blank.

To resolve this I think I had to call the setresolution method of the new bitmap and supply values. I think I got the values from a horizontalresolution method and a verticalresolution method.

It was a while ago I done this, I will check the code in work tomorrow to see exactly what i done

eakin
Jan 16th, 2007, 03:42 AM
string fullPathOfOriginalFilename = "c:\\soap\\100dpi.tif";
//original file
System.Drawing.Bitmap myBitmap;
myBitmap = new System.Drawing.Bitmap(fullPathOfOriginalFilename);


//size and position of area to be cropped
int cropX = 100;
int cropY = 100;
int cropWidth = 100;
int cropHeight = 100;


//a rectangle to set the location and size from the source image
Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);


//create a new bitmap with the width/height values
Bitmap imgCropped = new Bitmap(rect.Width, rect.Height);
imgCropped.SetResolution(myBitmap.HorizontalResolution, myBitmap.VerticalResolution);