-1

I'm writing procedure that rewrites bitmap to array on XE7. I wrote this piece of code:

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;

But it doesn't work, array is filled with zeros.

Bitmap:

1

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
meller92
  • 295
  • 1
  • 2
  • 14

1 Answers1

1

In the comments you said:

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

That's because an 8bpp bitmap uses a palette to identify colours. And in your palette, 0 identifies white, and 255 identifies black. That much can be deduced from the evidence that you present. However, it is also evident when you inspect the colour table in the .bmp file.

A palette is a table of colours. The table has 256 entries. Each pixel in the bitmap is an index into the table.

If you want to get the RGB colour for each pixel, you need to read the palette color table first, and then use the Scanline values as indexes into that table.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • I want to get only pixels intensity. How to set to monochrome bitmap that I load to TImage? – meller92 Apr 17 '15 at 15:58
  • I answered the question that you asked. Then I answered the next one. And indeed note, that the question text still doesn't match my answer. I've actually answered your second question which was asked in a comment. Now you have another question. This is unfair of you. You are meant to ask one question at a time. Anyway, it seems that I am not helping you, you are not finding what I write helpful, so should I stop? – David Heffernan Apr 17 '15 at 17:44