473,714 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ima ge.Save("C:\\DA TA\\PICTURES\\t estpic.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:

EncoderParamete rs encparams = new
EncoderParamete rs(1);
encparams.Param[0] = new
EncoderParamete r(System.Drawin g.Imaging.Encod er.ColorDepth, 256L);
ImageCodecInfo[] imcodecinfo =
ImageCodecInfo. GetImageEncoder s();
picturebox1.Ima ge.Save(("C:\\D ATA\\PICTURES\
\testpic.gif", imcodecinfo[0], encparams);

and more of the kind: Encoder.Compres sion, Encoder.Quality , etc.

This actually solves the problem, no matter what value I put after the
Encoder."someth ing": (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.Gi f" is 24 Kb.
The GIF made with Irfanview interlaced is 56 Kb (and this has the
quality I need).
Using these EncoderParamete rs, 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 4908
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.Ima ge.Save("C:\\DA TA\\PICTURES\\t estpic.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.ScanMet hod
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."someth ing": (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.Gi f" is 24 Kb.
The GIF made with Irfanview interlaced is 56 Kb (and this has the
quality I need).
Using these EncoderParamete rs, 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.Ima ge.Save(("C:\\D ATA\\PICTURES\\ testpic.gif",
imcodecinfo[1], encparams);

Please note the number [1] instead of the [0] following the
"imcodecinf o".
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.Ima ge.Save(("C:\\D ATA\\PICTURES\\ testpic.gif",
imcodecinfo[1], encparams);

Please note the number [1] instead of the [0] following the
"imcodecinf o".
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
8223
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 has a label which returns the color of a pixel that is in position x,y on the screen (i.e. the desktop @ 1024 x 768 pixels), where x and y are of course variable.
16
4181
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
8801
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9174
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7953
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6634
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4464
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2520
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2110
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.