|
|
|
start date: Thu, 16 Aug 2007 07:02:29 -0700,
posted on: microsoft.public.dotnet.framework.drawing
back
| Thread Index |
|
1
Nenefta
|
|
2
Bob Powell [MVP]
|
|
3
Nenefta
|
|
4
Michael Phillips, Jr. 0.c0m
|
Image Quality loss
As a beginner to GDI, I think I'm doing someting fairly
straightforward, loading and saving an image, but it seems te lead to
a loss of quality. What can be the reason for this loss, and how would
I go about it to fix this?
Thanx,
Marcel
I'm using the following code:
Dim bmap As Bitmap = New Bitmap(588, 477)
Dim graphics As Graphics = System.Drawing.Graphics.FromImage(bmap)
Dim img As Image = Image.FromFile("someimage.gif")
graphics.DrawImageUnscaled(img, 0, 0)
graphics.Dispose()
bmap.Save("targetimage.gif", Drawing.Imaging.ImageFormat.Gif)
bmap.Dispose()
Date:Thu, 16 Aug 2007 07:02:29 -0700
Author:
|
Re: Image Quality loss
GIF images saved by GDI+ will inevitabley suffer conversion losses because
the codec does not calculate a dedicated palette for the image but uses a
"spread palette" instead.
See my site for more details. Links below.
--
--
Bob Powell [MVP]
Visual C#, System.Drawing
Ramuseco Limited .NET consulting
http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"Nenefta" wrote in message
news:1187272949.619014.85870@a39g2000hsc.googlegroups.com...
> As a beginner to GDI, I think I'm doing someting fairly
> straightforward, loading and saving an image, but it seems te lead to
> a loss of quality. What can be the reason for this loss, and how would
> I go about it to fix this?
>
> Thanx,
> Marcel
>
> I'm using the following code:
>
>
> Dim bmap As Bitmap = New Bitmap(588, 477)
> Dim graphics As Graphics = System.Drawing.Graphics.FromImage(bmap)
>
> Dim img As Image = Image.FromFile("someimage.gif")
>
> graphics.DrawImageUnscaled(img, 0, 0)
> graphics.Dispose()
>
> bmap.Save("targetimage.gif", Drawing.Imaging.ImageFormat.Gif)
> bmap.Dispose()
>
Date:Thu, 16 Aug 2007 17:34:51 +0200
Author:
|
Re: Image Quality loss
Thank you for your answer, but I was unable to solve my problem
sofar.
I was able to have someone supply me a jpg image in good quality. When
I use the code mentioned earlier, the result is much better than
before. Still though, a few colors are different in the source and
target image. I even tried some practices mentioned on your website
using e.g. codec and EncoderParameter to save the bitmap in 100%
quality.
Which chapter on the website will point me in the right direction. Can
this problem be tackled?
Greets,
Marcel
On 16 aug, 17:34, "Bob Powell [MVP]"
wrote:
> GIF images saved by GDI+ will inevitabley suffer conversion losses because
> the codec does not calculate a dedicated palette for the image but uses a
> "spread palette" instead.
>
> See my site for more details. Links below.
>
> --
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Ramuseco Limited .NET consultinghttp://www.ramuseco.com
>
> Find great Windows Forms articles in Windows Forms Tips and Trickshttp://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQhttp://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
> "Nenefta" wrote in message
>
> news:1187272949.619014.85870@a39g2000hsc.googlegroups.com...
>
>
>
> > As a beginner to GDI, I think I'm doing someting fairly
> > straightforward, loading and saving an image, but it seems te lead to
> > a loss of quality. What can be the reason for this loss, and how would
> > I go about it to fix this?
>
> > Thanx,
> > Marcel
>
> > I'm using the following code:
>
> > Dim bmap As Bitmap = New Bitmap(588, 477)
> > Dim graphics As Graphics = System.Drawing.Graphics.FromImage(bmap)
>
> > Dim img As Image = Image.FromFile("someimage.gif")
>
> > graphics.DrawImageUnscaled(img, 0, 0)
> > graphics.Dispose()
>
> > bmap.Save("targetimage.gif", Drawing.Imaging.ImageFormat.Gif)
> > bmap.Dispose()- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -
Date:Wed, 22 Aug 2007 05:48:23 -0700
Author:
|
Re: Image Quality loss
> Can this problem be tackled?
Your code snippet creates an empty 32bpp bitmap with dimensions of 588 x
477.
You then load a gif of unknown dimensions and unpack it from an indexed 8bpp
image to a 32bpp bitmap by drawing it unscaled.
As Bob mentioned, the gif encoder must take the resultant 32bpp bitmap and
create an indexed 8bpp gif image.
Since the encoder needs a palette to index the bitmap, it uses a spread
palette.
The colors in the destination palette will never match the source.
One way to tackle your problem is to get the color quantization reduction
algorithm code from MSDN and create the best palette representative of the
colors in the 32bpp bitmap and use that palette to index your 8bpp gif.
The code is here:
http://msdn2.microsoft.com/en-us/library/Aa479306.aspx
Bob's code for gif palettes is here:
http://www.bobpowell.net/giftransparency.htm
Since the System.Drawing API cannot create a Graphics context for an indexed
8bpp bitmap the above is your only option using this API.
"Nenefta" wrote in message
news:1187786903.455265.313330@x40g2000prg.googlegroups.com...
> Thank you for your answer, but I was unable to solve my problem
> sofar.
>
> I was able to have someone supply me a jpg image in good quality. When
> I use the code mentioned earlier, the result is much better than
> before. Still though, a few colors are different in the source and
> target image. I even tried some practices mentioned on your website
> using e.g. codec and EncoderParameter to save the bitmap in 100%
> quality.
>
> Which chapter on the website will point me in the right direction. Can
> this problem be tackled?
>
> Greets,
> Marcel
>
>
>
> On 16 aug, 17:34, "Bob Powell [MVP]"
> wrote:
>> GIF images saved by GDI+ will inevitabley suffer conversion losses
>> because
>> the codec does not calculate a dedicated palette for the image but uses a
>> "spread palette" instead.
>>
>> See my site for more details. Links below.
>>
>> --
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Ramuseco Limited .NET consultinghttp://www.ramuseco.com
>>
>> Find great Windows Forms articles in Windows Forms Tips and
>> Trickshttp://www.bobpowell.net/tipstricks.htm
>>
>> Answer those GDI+ questions with the GDI+
>> FAQhttp://www.bobpowell.net/faqmain.htm
>>
>> All new articles provide code in C# and VB.NET.
>> Subscribe to the RSS feeds provided and never miss a new article.
>>
>> "Nenefta" wrote in message
>>
>> news:1187272949.619014.85870@a39g2000hsc.googlegroups.com...
>>
>>
>>
>> > As a beginner to GDI, I think I'm doing someting fairly
>> > straightforward, loading and saving an image, but it seems te lead to
>> > a loss of quality. What can be the reason for this loss, and how would
>> > I go about it to fix this?
>>
>> > Thanx,
>> > Marcel
>>
>> > I'm using the following code:
>>
>> > Dim bmap As Bitmap = New Bitmap(588, 477)
>> > Dim graphics As Graphics = System.Drawing.Graphics.FromImage(bmap)
>>
>> > Dim img As Image = Image.FromFile("someimage.gif")
>>
>> > graphics.DrawImageUnscaled(img, 0, 0)
>> > graphics.Dispose()
>>
>> > bmap.Save("targetimage.gif", Drawing.Imaging.ImageFormat.Gif)
>> > bmap.Dispose()- Tekst uit oorspronkelijk bericht niet weergeven -
>>
>> - Tekst uit oorspronkelijk bericht weergeven -
>
>
Date:Wed, 22 Aug 2007 12:48:57 -0400
Author:
|
|
|