Board index » delphi » TGifImage colors wrong on saving

TGifImage colors wrong on saving

When I try to save a gif using Anders Melander's TGifImage the colors
are off. Anyone know why?

thanks in advance

___
Free Project Time Tracker for Delphi Developers
http://www.{*word*104}-matrix.com/pcdelphi.html

 

Re:TGifImage colors wrong on saving


I have never tried to save a gif.
One thing that comes to mind when you say the colours are off:
Maybe the palette is not set correctly.
Can you you show me the complete gif saving code you use so I can try it?
--
Finn Tolderlund

"Michael Fullerton" <full...@spamkiller-remove.{*word*104}-matrix.com> wrote in
message news:3db80577.68298057@forums.borland.com...

Quote
> When I try to save a gif using Anders Melander's TGifImage the colors
> are off. Anyone know why?

Re:TGifImage colors wrong on saving


Quote
"Lee Parker" <lpar...@mountville.com> wrote:
>TGifImage reduces the number of colors in the image.  You may want to set
>the way an image is dithered, and what the colors are reduced to...  You'll
>want to use an optimized palette (just a setting) to get the best match on
>colors, but I don't remember it.  The following like of code reduces a
>bitmap image to a 5bit custom color palette using Floyd Steinberg error
>difussion dithering:

>    // Reduce Color Resolution

>Image.Picture.Assign(GifImage.ReduceColors(BMap,rmPalette,dmFloydSteinberg,5
>,CreatePalette(BPal.p)));

>My best guess for what you are looking for is something like:

>procedure SaveBmpToGif(BMap :TBitmap; Filename: string);
>var
>  MyGif : TGifImage;
>begin
>    MyGif := TGifImage.Create;
>    MyGif.ColorResolution := 8;

The compiler complains at the above line: "Cannot assign to a
read-only property". Commenting it out gives the same effect.

I also tried the Optimize method:
      Optimize([],rmQuantize,dmNearest,255);

Same problem. (Not really sure what to use for the last value though)

Note that I only tried saving screen shots and the only color that
seems to be off is the ordinary Windows grey.

here's a bad shot made by my function:
http://www.{*word*104}-matrix.com/screens/ivmain.gif

here's a good one not made by my function:
http://www.{*word*104}-matrix.com/screens/ivconfig.gif

- Show quoted text -

Quote
>    MyGif.ColorReduction := rmQuantize; // use best 2^8 (256) colors
>    MyGif.DitherMode := dmNearest;  // no dither, use nearest color in
>palette
>    MyGif.Assign(BMap);
>    MyGif.SaveToFile(Filename);
>    MyGif.Free;
>end;

>Later,
>Lee

>"Michael Fullerton" <full...@spamkiller-remove.{*word*104}-matrix.com> wrote in
>message news:3db80577.68298057@forums.borland.com...
>> When I try to save a gif using Anders Melander's TGifImage the colors
>> are off. Anyone know why?

>> thanks in advance

___
Free Project Time Tracker for Delphi Developers
http://www.{*word*104}-matrix.com/pcdelphi.html

Re:TGifImage colors wrong on saving


What about this:
Quote
> procedure SaveBmpToGifFile(Image: TImage; sFilePath: string);
> var
>   MyGif : TGifImage;
> begin
>     MyGif:= TGifImage.Create;
>     with MyGif do begin

            ColorReduction := rmQuantizeWindows;
            DitherMode := dmFloydSteinberg;
Quote
>       Assign(Image.Picture.Bitmap);
>       SaveToFile(sFilePath);
>       Free;
>     end;
> end;

--
Finn Tolderlund

"Michael Fullerton" <full...@spamkiller-remove.{*word*104}-matrix.com> skrev i en
meddelelse news:3db963b9.55756042@forums.borland.com...

Quote
> procedure SaveBmpToGifFile(Image: TImage; sFilePath: string);
> var
>   MyGif : TGifImage;
> begin
>     MyGif:= TGifImage.Create;
>     with MyGif do begin
>       Assign(Image.Picture.Bitmap);
>       SaveToFile(sFilePath);
>       Free;
>     end;
> end;

Re:TGifImage colors wrong on saving


Quote
"Finn Tolderlund" <n...@spam.dk> wrote:
>What about this:
>> procedure SaveBmpToGifFile(Image: TImage; sFilePath: string);
>> var
>>   MyGif : TGifImage;
>> begin
>>     MyGif:= TGifImage.Create;
>>     with MyGif do begin
>            ColorReduction := rmQuantizeWindows;
>            DitherMode := dmFloydSteinberg;
>>       Assign(Image.Picture.Bitmap);
>>       SaveToFile(sFilePath);
>>       Free;
>>     end;
>> end;

Thanks but it gives the exact same problem.

___
Free Project Time Tracker for Delphi Developers
http://www.{*word*104}-matrix.com/pcdelphi.html

Re:TGifImage colors wrong on saving


How many different colours are in your bitmap?
--
Finn Tolderlund

"Michael Fullerton" <full...@spamkiller-remove.{*word*104}-matrix.com> skrev i en
meddelelse news:3db9c5ed.80896643@forums.borland.com...

Quote
> Thanks but it gives the exact same problem.

Re:TGifImage colors wrong on saving


Quote
"Finn Tolderlund" <n...@spam.dk> wrote:
>How many different colours are in your bitmap?

Well in the original bmp there are 16113 unique colors. In the gif
created by IfranView there are 256 unique colors (and it looks fine).
In the gif created by me there are 122 unique colors.

Quote
>"Michael Fullerton" <full...@spamkiller-remove.{*word*104}-matrix.com> skrev i en
>meddelelse news:3db9c5ed.80896643@forums.borland.com...
>> Thanks but it gives the exact same problem.

___
Free Project Time Tracker for Delphi Developers
http://www.{*word*104}-matrix.com/pcdelphi.html

Re:TGifImage colors wrong on saving


Then the problem must be in the algorithm used to reduce the 16113 colors to
256 or less.
If you post your bmp and the good gif and the bad gif in the .attachment
group I will try to look at it.
--
Finn Tolderlund

"Michael Fullerton" <full...@spamkiller-remove.{*word*104}-matrix.com> skrev i en
meddelelse news:3dbd6b60.5084160@forums.borland.com...

Quote

> >How many different colours are in your bitmap?

> Well in the original bmp there are 16113 unique colors. In the gif
> created by IfranView there are 256 unique colors (and it looks fine).
> In the gif created by me there are 122 unique colors.

Re:TGifImage colors wrong on saving


Quote
"Finn Tolderlund" <n...@spam.dk> wrote:
>Then the problem must be in the algorithm used to reduce the 16113 colors to
>256 or less.
>If you post your bmp and the good gif and the bad gif in the .attachment
>group I will try to look at it.

Great, thank you very much. I posted them in attachments under the
same subject heading.

___
Free Project Time Tracker for Delphi Developers
http://www.{*word*104}-matrix.com/pcdelphi.html

Other Threads