M
Mike Bridge
I have a method, taken from the web somewhere, for resizing a jpeg
which works well, using the System.Drawing.Graphics class. But
Graphics won't accept PixelFormats that are indexed---in my case, Gif
images---so I have to convert these to a non-indexed PixelFormat. The
problem is that when I convert these from a gif to a non-indexed
Image, then back to a Gif again, I not only lose the transparency, but
the resulting quality is poor.
Is there a correct way to do this in dotnet? My goal is to be able to
resize any .jpg or .gif (transparent or not).
Here is what I'm doing now :
Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(origimage.HorizontalResolution,
origimage.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.DrawImage(origimage,
new Rectangle(0,0,newWidth,newHeight),
new Rectangle(0,0,origimage.Width,origimage.Height),
GraphicsUnit.Pixel);
grPhoto.Dispose();
Thanks,
-Mike
which works well, using the System.Drawing.Graphics class. But
Graphics won't accept PixelFormats that are indexed---in my case, Gif
images---so I have to convert these to a non-indexed PixelFormat. The
problem is that when I convert these from a gif to a non-indexed
Image, then back to a Gif again, I not only lose the transparency, but
the resulting quality is poor.
Is there a correct way to do this in dotnet? My goal is to be able to
resize any .jpg or .gif (transparent or not).
Here is what I'm doing now :
Bitmap bmPhoto = new Bitmap(newWidth, newHeight,
PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(origimage.HorizontalResolution,
origimage.VerticalResolution);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.DrawImage(origimage,
new Rectangle(0,0,newWidth,newHeight),
new Rectangle(0,0,origimage.Width,origimage.Height),
GraphicsUnit.Pixel);
grPhoto.Dispose();
Thanks,
-Mike