Delphi TBitmap - why are Pixels and ScanLine different?

When using 32-bit TBitmap, I switched from Canvas.Pixels to ScanLine.

Then I set the value to "Red", only to find it as blue.

Any idea why?

Here is the code excerpt:

procedure TForm1.FormPaint(Sender: TObject);
var
  varBitmap: TBitmap;
  pLock: PIntegerArray;
  iColor: integer;
begin
  varBitmap := TBitmap.Create;
  varBitmap.PixelFormat := pf32bit;
  varBitmap.Width := 800;
  varBitmap.Height := 600;

  // Set Pixels to Red
  varBitmap.Canvas.Pixels[0, 0] := $0000FF;

  // Shows $FF0000 (blue)
  pLock := varBitmap.ScanLine[0];
  iColor := pLock[0];
  ShowMessageFmt('%x', [iColor]);

  // Set ScanLine to Red
  pLock[0] := $0000FF;

  // Displays a blue pixel
  Canvas.Draw(0, 0, varBitmap);
end;

It seems that TColor is somehow different from what it has in mind, but that doesn't make sense.

Any suggestions are welcome .;)

+4
source share
2 answers

32-bit pixel data is in format $AARRGGBB. You are installing the Blue component, not the red component. Use $FF0000instead $0000FF. Or better, use a function RGB().

+5

VCL, TBitmap (DIB). . , 32 , , . , .

, , - Pixels TCanvas ScanLine TBitmap.

Pixels TCanvas GDI GetPixel SetPixel. , COLORREF. COLORREF :

; ; . . - 0xFF.

, COLORREF . GetPixel SetPixel COLORREF . , a COLORREF -. COLORREF $00BBGGRR.

, ScanLine TBitmap DIB. , , - 32- , , $AARRGGBB. Windows 32bpp- :

2 ^ 32 . biCompression BITMAPINFOHEADER BI_RGB, bmiColors BITMAPINFO NULL. DWORD , . 8 , 8 . DWORD .

, . DWORD , , -, .

+6

Source: https://habr.com/ru/post/1530901/


All Articles