5

I have a gif image of 80x40 pixels. The color palette of this image consists of a few similar colors that have different numbers in the palette. How can I build a 2d array where the cell at x,y will be a number of the color in the palette?

Kevin
  • 53,822
  • 15
  • 101
  • 132
Yazon2006
  • 3,684
  • 3
  • 25
  • 36
  • 1
    Direct access to X-th element of Y-th `Scanline` will give you desired index of color table. – OnTheFly Jul 07 '13 at 03:59
  • Can anyone explain why this question is put on hold as off-topic? – Wouter van Nifterick Jul 07 '13 at 11:08
  • 1
    It's actually a good question that could have a clear answer if it wasn't blocked by people who probably don't even understand the question. 3 of the closers have never posted any question or answer with a Delphi tag. – Wouter van Nifterick Jul 07 '13 at 11:19
  • 1
    @TLama: Yay, the new closing system on this site works! Thanks for re-opening, mate. Now if only the badge-whoring-JQuery-guru's would get off our Delphi lawn, we'll get somewhere :) – Wouter van Nifterick Jul 07 '13 at 13:51

2 Answers2

3

TGifImage has such an array built in, so just make use of it:

var 
  Gif:TGifImage;
  PaletteIndex : byte;
begin
  Gif := TGifImage.Create;

  // ... load your stuff here ...

  // TGifImage has an Images property, which is probably only interesting if you're dealing with animations, so just take the first image.
  PaletteIndex := Gif.Images[0].Pixels[0,0]; // palette index for top-left pixel 

  // Now, to get the actual TColor for that pixel, you could do this:
  Self.color := Gif.Images[0].ColorMap.Colors[PaletteIndex];

end;
Wouter van Nifterick
  • 23,603
  • 7
  • 78
  • 122
-1

You can load your image into a TBitmap. Then you can use the ScanLine property of a TBitmap class. This indexed property takes a 0 based index of a row and returns a pointer to pixel values for that row. Take a look at this page to learn more about ScanLine property.

TLama
  • 75,147
  • 17
  • 214
  • 392
Nima
  • 379
  • 3
  • 15