How to access TBitmap pixels directly in FMX2 (replacing TBitmap.ScanLine)?

The FMX.Types.TBitmap class has the ScanLine property in FMX (FireMonkey), but it seems that this property has been deleted and is missing in FMX2 (FireMonkey FM2).

Is there a workaround? How can we access TBitmap content directly in FMX2?

+4
source share
2 answers

For direct access, you expect to use the Map method. The documentation includes a number of examples, such as FMX.AlphaColorToScanline :

 function TForm1.TestAlphaColorToScanline(ABitmap: TBitmap; start, count: integer): TBitmap; var bitdata1, bitdata2: TBitmapData; begin Result := TBitmap.Create(Round(ABitmap.Width), Round(count)); if (ABitmap.Map(TMapAccess.maRead, bitdata1) and Result.Map(TMapAccess.maWrite, bitdata2)) then begin try AlphaColorToScanline(@PAlphaColorArray(bitdata1.Data) [start * (bitdata1.Pitch div GetPixelFormatBytes(ABitmap.PixelFormat))], bitdata2.Data, Round(Result.Height * Result.Width), ABitmap.PixelFormat); finally ABitmap.Unmap(bitdata1); Result.Unmap(bitdata2); end; end; end; 
+6
source

Here is an example for C ++ Builder (current documents are completely absent):

 int X, Y; TBitmapData bm; // get bitmap data access ! if ( Image1->Bitmap->Map(TMapAccess::maReadWrite, bm) ) { unsigned int* data = (unsigned int*)bm.Data; // ie clear data with alpha color memset(data, 0, Image1->Width * Image1->Height * sizeof(unsigned int)); // test direct pixel access here for (X = 20; X <= 200; X++) { for (Y = 10; Y <= 100; Y++) { //MyBitmap->Pixels[X][Y] = claLime; // does not work anymore ! bm.SetPixel(X, Y, claLime); } } // now write back the result ! Image1->Bitmap->Unmap(bm); } else { MessageDlg("Could not map the image data for direct access.", TMsgDlgType::mtWarning, TMsgDlgButtons() << TMsgDlgBtn::mbOK, 0); } 
+2
source

All Articles