Last post Jun 17, 2010 04:38 AM by ereko
Jun 15, 2010 04:35 PM|ereko|LINK
I have been searching on the internet to find a function that can convert given gif file into jpg file. I mean it should not just change the extension. I need that function in order to get rid of "A Graphics object cannot be created from an image that
has an indexed pixel format." error. I hope that there is such a function.
Jun 15, 2010 04:53 PM|hajan|LINK
Check the following discussion:
http://www.velocityreviews.com/forums/t67481-convert-gif-to-jpg.html and see the code.
Jun 15, 2010 05:11 PM|rollo1002|LINK
The following code should fix the error it will not convert the image just remove the error.
Image img = Image.FromStream(new MemoryStream(imgA));
Bitmap imgB = new Bitmap(new Bitmap( img ));
catch (Exception ex)
Jun 15, 2010 06:22 PM|ereko|LINK
I am using webcropimage tool to crop images and it only manipulated jpg files and throw errors for gif files. But I am not sure I can embed this code into it.
Jun 15, 2010 06:26 PM|rollo1002|LINK
so are you just trying to convert a .jpg file that is on your computer to a gif file that resides on your computer?
If that is the case here is an online tool that you can use:
Jun 16, 2010 12:56 AM|ereko|LINK
Users will be able to upload gif files and system should deal with converting.
Hajan, this code displays the image and does not save it. In addition, it does not show how to get file with path. Am I wrong?
Jun 16, 2010 04:13 AM|hajan|LINK
the Image.Save() method which is instance of Bitmap class, has 5 overloaded methods that can be used for saving the Image .
1. Image.Save(string filename);
2. Image.Save(string filename, ImageFormat format);
3. Image.Save(Stream stream, ImageFormat format);
4. Image.Save(string filename, ImageCodecInfo encoder, EncoderParameters encoderParams);
5. Image.Save(Stream stream, ImageCodecInfo encoder, EncoderParameters encoderParams);
- use the one that fits your needs.
Jun 16, 2010 04:14 AM|hajan|LINK
One more example for saving Bitmap to file:
Jun 17, 2010 04:38 AM|ereko|LINK
Thanks for the last example. This code successfully makes the conversion from gif to jpg :
System.Drawing.Image Img = System.Drawing.Image.FromFile(filepc.PostedFile.FileName);
Bitmap bmp1 = new Bitmap(Img, Img.Width, Img.Height);
// Save the image as a GIF.
bmp1.Save("path + filename.jpg" , System.Drawing.Imaging.ImageFormat.Jpeg);