473,385 Members | 1,487 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to save a .GIF - "interlaced" ?

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\\testpi c.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.Co lorDepth, 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
Jun 27 '08 #1
7 4877
On Mon, 09 Jun 2008 23:32:58 -0700, Mads Aggerholm
<ma************@gmail.comwrote:
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\\testpi c.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#?
Interlaced has nothing to do with image quality. It simply controls
whether the scan lines of the image are stored sequentially or not. When
the image is interlaced, then an image being downloaded can be presented
in a usefully partial way before the entire download has completed.

In theory, you could probably control this with the Encoder.ScanMethod
encoding parameter. But a) it would have no effect on your image quality,
and b) if I read the docs right, it's not currently supported in .NET
anyway.

I admit, it's hard to know whether I'm right about the latter point. The
docs regarding image encoding for .NET are surprisingly useless. :)
[...]
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.
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. :)

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? Again, if the docs weren't so vague, I'm sure they'd
explain that (or else explain that the argument could in fact just be a
regular "int").

If using a more reasonable color depth doesn't change the behavior, then I
don't know. Without a concise-but-complete code sample, along with a
single image file posted somewhere that it can be downloaded for use with
the code example, it's not really possible to say. For all we know, the
problem is as simple as you not actually emitting an image file of
different pixel dimensions from your program as in the image conversion
program (either because you start with different-sized images, or because
the output is specifically created as different sizes).

Pete
Jun 27 '08 #2
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
Jun 27 '08 #3
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\\testp ic.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

Jun 27 '08 #4
On Tue, 10 Jun 2008 03:47:39 -0700, Mads Aggerholm
<ma************@gmail.comwrote:
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\\testp ic.gif",
imcodecinfo[1], encparams);

Please note the number [1] instead of the [0] following the
"imcodecinfo".
Well, yes. It would be imperative that you use the correct encoder. :)

Actually, most code I've seen enumerates that list to find the appropriate
encoder, rather than just picking one at random. You might want to do
that, rather than just assuming that the one you want is in the 1st (or
0th) position.

Sorry I didn't mention that earlier...I got distracted trying to figure
out why MSDN is so lame about documenting all this stuff.

Pete
Jun 27 '08 #5
Hello, i carefully read your last post talking about the GIF parameters and I cannot find the right expression to save my picture as a GIF file with good quality.

Could you post your code here ?

Thanks in advance
Sep 17 '08 #6
Hello, i carefully read your last post talking about the GIF parameters and I cannot find the right expression to save my picture as a GIF file with good quality.

Could you post your code here ?

Thanks in advance
Sep 17 '08 #7
"Olivier Montiel" wrote in message news:20*****************@free.fr...
Hello, i carefully read your last post talking about the GIF parameters
and I cannot find the right expression to save my picture as a GIF file
with good quality.

Could you post your code here ?
See:-

http://support.microsoft.com/kb/319061

--
Anthony Jones - MVP ASP/ASP.NET

Sep 18 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: grogerteal | last post by:
Hello, I am pretty new to programming and would like someone to help me get started on the program that I need to make. I hope it is not hard to do, but what I would like is a simple app that...
16
by: saurabhnsit2001 | last post by:
The following program doesn't "seem" to print "hello-out". (Try executing it) #include <stdio.h> #include <unistd.h> int main() { while(1) { fprintf(stdout,"hello-out");
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.