saving a ".gif" image gives me problems

M

monfu

Dear all

I have the following code:-

System.Drawing.Image src_image
System.Drawing.Image.FromStream(imgStream);

Bitmap bitmap = new Bitmap(image_width, image_height
src_image.PixelFormat);
Graphics new_g = Graphics.FromImage(bitmap);
new_g.SmoothingMode
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
new_g.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
new_g.SmoothingMode = SmoothingMode.HighQuality;
new_g.CompositingQuality
System.Drawing.Drawing2D.CompositingQuality.HighQuality;
new_g.CompositingMode
System.Drawing.Drawing2D.CompositingMode.SourceCopy;

new_g.DrawImage(src_image, 0, 0, bitmap.Width, bitmap.Height);
new_g.Save();
src_image.Dispose();

System.Drawing.Imaging.Encoder Enc
System.Drawing.Imaging.Encoder.Transformation;
EncoderParameters EncParms = new EncoderParameters(1);

EncParms.Param = new EncoderParameter[]
{
new EncoderParameter(Enc,(long)EncoderValue.CompressionLZW),
new EncoderParameter(System.Drawing.Imaging.Encoder.Quality
100L)
};

ImageCodecInfo ici ;

ici = GetProperEncoder(image_name);

string newFullPath = path + image_name;

bitmap.Save(newFullPath, System.Drawing.Imaging.ImageFormat.Jpeg);

bitmap.Dispose();
new_g.Dispose();

which is working fine when i upload a "jpg" image. However, when
tried to upload a ".gif" image, it is not working fine. It is givin
me the following error:-

"A Graphics object cannot be created from an image that has an indexe
pixel format."

I am not saving the image prior to uploading, just putting it in
stream and saving the image after the manipulation is done.

Thanks for your help

Johan
 

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

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top