How to resize a transparent GIF?

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
 
C

Cor

Hi Mike,

Herfried. K. Wagner did supply today this piece of sample in the dotnet.vb
newsgroup.
I did not try it yet. But when Herfried makes this kind of samples the
almost always are right.
But when not, ask it in the newsgroup microsoft.public.dotnet.languages.vb
and refer to this sample and tell my name and from Herfried.

Cor

\\\By Herfried K. Wagner
Dim bmp As New Bitmap( _
"C:\Lagoon1024x768.bmp" _
)
Dim bmp2 As New Bitmap( _
bmp.Width * 0.1, _
bmp.Height * 0.1, _
Imaging.PixelFormat.Format24bppRgb _
)
Dim g As Graphics = Graphics.FromImage(bmp2)

' Select/change interpolation mode here.
g.InterpolationMode = _
Drawing.Drawing2D.InterpolationMode.HighQualityBicubic

' Draw image using specified interpolation mode.
g.DrawImage(bmp, 0, 0, bmp2.Width, bmp2.Height)
g.Dispose()

Me.PictureBox1.Image = bmp2
///

You can call 'bmp2''s 'Save' method to write the bitmap to a file.
There you can specify the destination image format too.

I hope this helps a little bit?

Cor
 
C

Cor

Hi Mike,

I did mean when not good for a "transparant" GIF for the rest I trust on
Herfried.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top