Saving images after using MakeTransparent() creates huge files
Question posted by: jbro22
(Newbie)
on
August 22nd, 2008 05:44 PM
Hello, I am working on a project in which it is necessary to convert a jpg image which contains lots of black surrounding the actual photograph to a transparent gif in which the black has become transparent. Cropping is not an option because the images are aerial photography, so the "true image" is never the same shape.
My problem is that when I use the MakeTransparent() function and then save it as a gif, the filesize skyrockets from 4MB to 13MB. I would understand it going up to maybe 5.5 since I am adding another channel, but why is it going that far?
MakeTransparent seems to be my only option since going through pixel by pixel would take far to long for the thousands of pictures I have. Here are two pieces of code that I have tried. In the first I just save it as a file name (.gif) and don't tell it the image format. This results in the transparency I desire, but at 13MB. In the second option I specify that the new image is of the gif format. This results in a .gif that is now 1.5MB, but with no transparency at all (still black). Neither of these are usable options.
Code 1:
System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(Pic);
bmp1.MakeTransparent(Color.Black);
bmp1.Save("test.gif");
Code 2:
System.Drawing.Bitmap bmp1 = new System.Drawing.Bitmap(Pic);
bmp1.MakeTransparent(Color.Black); bmp1.Save("test.gif",System.Drawing.Imaging.ImageFormat.Gif);
Thanks so much in advance!
~John
4
Answers Posted
This code doesn't look like C++ to me; does this question go in the java forum?
No you are right it is not C++ but it is C# and I couldn't find another forum topic that was closer than C++. Any suggestions on where I should place it? Thanks
I think C# goes in the .NET forum; a moderator should be able to move this thread.
just so i understand. you are trying to turn all the pixels that are black, to another color? in this case Transparent?
|
|
|
What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 197,045 network members.
|