Delphi XE7 上的位图到数组

Bitmap to Array on Delphi XE7

我正在编写在 XE7 上将位图重写为数组的程序。我写了这段代码:

PROCEDURE BitmapToArray(var inBitmap : TBitMap;
                      var outArray : TIntegerDynArray_2D);
var
x   : integer;
y   : integer;

P   : PByteArray;
begin
 SetLength(outArray,0,0);
 SetLength(outArray, inBitmap.Height, inBitmap.Width);
 for y := 0 to inBitmap.Height-1 do
  begin
    P := inBitmap.ScanLine[y];
    for x := 0 to inBitmap.Width-1 do
      begin
      outArray[y,x]:=P[x];
      end;
   end;

end;

但这不起作用,数组中填满了零。

位图:

评论中你说:

I've recompiled the code and It's better, it scans .bmp but return inverse values of pixels 0 - white, 255-black.

这是因为 8bpp 位图使用调色板来识别颜色。在您的调色板中,0 表示白色,255 表示黑色。从你提供的证据中可以推断出这么多。但是,当您检查 .bmp 文件中的颜色 table 时也很明显。

调色板是 table 种颜色。 table 有 256 个条目。位图中的每个像素都是 table.

的索引

如果要获取每个像素的 RGB 颜色,需要先读取调色板颜色 table,然后使用 Scanline 值作为 table 的索引.