【问题标题】:Delphi. Convert Bitmap image to 2D Array德尔福。将位图图像转换为二维数组
【发布时间】:2013-07-04 16:53:55
【问题描述】:

我有一个 80x40 像素的 gif 图像。此图像的调色板由几个相似的颜色组成,这些颜色在调色板中有不同的数字。如何构建一个二维数组,其中x,y 的单元格将是调色板中颜色的数字?

【问题讨论】:

  • 直接访问第 Y 个 Scanline 的第 X 个元素将为您提供所需的颜色表索引。
  • 谁能解释为什么这个问题被搁置为题外话?
  • 这实际上是一个很好的问题,如果它没有被可能甚至不理解这个问题的人阻止,它可能会有一个明确的答案。 3 个关闭者从未发布过任何带有 Delphi 标签的问题或答案。
  • @TLama:是的,这个网站上的新关闭系统有效!谢谢你重新打开,伙计。现在,如果只有徽章-嫖客-JQuery-guru 能够离开我们的 Delphi 草坪,我们就会到达某个地方:)

标签: arrays delphi bitmap 2d palette


【解决方案1】:

您可以将图像加载到TBitmap。然后您可以使用TBitmap 类的ScanLine 属性。此索引属性采用基于 0 的行索引,并返回指向该行像素值的指针。查看this page 以了解有关ScanLine 属性的更多信息。

【讨论】:

  • 这不是问题发布者的意思。他想知道调色板中的索引,而不是扫描线中的索引。
  • 很遗憾扫描线无法正常工作,但感谢您的回答!
【解决方案2】:

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;

【讨论】:

  • 顺便说一句,这可能是我感谢 Anders Melander 捐赠 vcl.Imaging.GIFImg.pas 的好地方
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-08
  • 1970-01-01
  • 2013-06-21
  • 2011-08-22
  • 1970-01-01
  • 2018-05-13
相关资源
最近更新 更多