Last post Mar 27, 2011 03:46 PM by smirnov
Mar 25, 2011 12:01 PM|oneuser|LINK
I am using Graphics object to resize and crop an image and then finally save it to the disk.
I am either able to resize or crop but not both.
May be I am not passing the parameters to the graphics object correctly.
Mar 25, 2011 12:21 PM|oneuser|LINK
Just to add that my original image is of size 50 * 50.
I would first need to increase the size to 100 * 100 and then crop it to fit in 75 * 75 size.
(the requirement is not to scale it to 75 * 75 directly.
but to first resize to 100 * 100 and then crop it to 75 * 75 and then saving it.)
I think I am not using the Graphic object and Image object in the right way , passing it dimensions in wrong locations and hence it is either cropping or resizing but not doing both. Please help.
Mar 27, 2011 03:46 PM|smirnov|LINK
System.Drawing.Image original_size = System.Drawing.Image.FromStream(ms);
System.Drawing.Image i = new Bitmap(original_size, 100, 100);
Graphics graphic = Graphics.FromImage(i);
graphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;
graphic.DrawImage(i, 0, 0, 100, 100);
/* crop */
MemoryStream imgMemoryStream = new MemoryStream();
Bitmap bmp = new Bitmap(75, 75, PixelFormat.Format24bppRgb);
Graphics graphic_crop = Graphics.FromImage(bmp);
graphic_crop.DrawImage(i, new Rectangle(0, 0, 75, 75), 0, 0, 75, 75, GraphicsUnit.Pixel);