문제

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?

도움이 되었습니까?

해결책

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;

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top