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?
Asked
Active
Viewed 1,850 times
5
-
1Direct 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
-
1It'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 Answers
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
-
1By the way, this might be a good place to show my appreciation to Anders Melander for donating vcl.Imaging.GIFImg.pas – Wouter van Nifterick Jul 07 '13 at 14:05
-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.
-
3This is not what the poster of the question means. He wants to know the index in the color palette, not the index in the scanline. – Wouter van Nifterick Jul 07 '13 at 11:14
-