我有80x40像素的gif图像。该图像的调色板由一些相似的颜色组成,这些调色板中的数字不同。如何建立2d数组,其中x,y的单元格将是调色板中颜色的数量?

最佳答案

TGifImage内置了这样一个数组,因此只需使用它:

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;

07-24 09:25