How to save a .GIF - "interlaced" ?

M

Mads Aggerholm

Hello Sirs,

I am having a BMP loadet into a picturebox. This I'd like to save on
my harddisk as a GIF:

picturebox1.Image.Save("C:\\DATA\\PICTURES\\testpic.gif",
ImageFormat.Gif);

However, this GIF-file is not in very good quality.

Using "Irfanview", I can change a BMP-file to GIF in quite better
quality setting an option called "save interlaced".

How am I going to do that using C#?

I have allready tried:

EncoderParameters encparams = new
EncoderParameters(1);
encparams.Param[0] = new
EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 256L);
ImageCodecInfo[] imcodecinfo =
ImageCodecInfo.GetImageEncoders();
picturebox1.Image.Save(("C:\\DATA\\PICTURES\
\testpic.gif", imcodecinfo[0], encparams);

and more of the kind: Encoder.Compression, Encoder.Quality, etc.

This actually solves the problem, no matter what value I put after the
Encoder."something": (16L, 32L, 256L - why the "L" by the way??)

The only problem here is, that this GIF-file i about 7 times as big as
nessasary.
The GIF file saved with the "ImageFormat.Gif" is 24 Kb.
The GIF made with Irfanview interlaced is 56 Kb (and this has the
quality I need).
Using these EncoderParameters, the GIF ends up being 359 Kb.

This is a problem! By different reasons it is important that the files
are as small as possible, and I have to use GIF.

The fact that Irfanview can do this, tells me it can be done.

Can anybody in here tell me how?

Thank you very much in advance.

Sincerely / Best regards
Mads Aggerholm
 
M

Mads Aggerholm

Hi Pete,

Thanks for your reply.
Again, hard to say given how impossibly vague the documentation is, but  
what happens when you use 24L instead of 256L?  A bit-depth of 256 bits  
per pixel would certainly result in a much larger file.  :)

I don't have a "bit-depth". I have colordepth, which I tried to set to
24L. No change in size.

If I look at the proberties of the "interlaced" gif-file, it says it
has a bit-depth of 8.
"My" gif file, saved with the encoding, has a bitdepth of 24. No
matter what I do.

Does my encoding-part do anything at all?? The result is always the
same, no matter what I change??
By the way, the L tells the compiler to make the argument an Int64, aka  
"long".  Why the color depth encoder parameter needs to be specified as a  
"long", I don't know, but I did see other examples doing it that way, so  
why rock the boat?

Thanks for the explanation and you suggestions.

Sincerely / Best regards
Mads Aggerholm
 
M

Mads Aggerholm

Hello again.

Now it seems to work.
I was a little puzzled about _nothing_ changed whatever I did.
This made me make this change:

picturebox1.Image.Save(("C:\\DATA\\PICTURES\\testpic.gif",
imcodecinfo[1], encparams);

Please note the number [1] instead of the [0] following the
"imcodecinfo".
Now I have a GIF on 48 Kb with fine quality.

Problem solved!

Sincerely / Best regards
MadsAggerholm
 

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