FMX.Types.TBitmap
类在FMX(FireMonkey)中具有ScanLine
属性,但似乎此属性已被删除,并且在FMX2(FireMonkey FM2)中缺失。
有没有解决方法?我们如何直接在FMX2中访问TBitmap
内容?
答案 0 :(得分:7)
对于直接访问,您应该使用Map
方法。该文档包含许多示例,例如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;
答案 1 :(得分:2)
以下是C ++ Builder的一个示例(当前的文档完全缺失):
int X, Y;
TBitmapData bm;
// get bitmap data access !
if ( Image1->Bitmap->Map(TMapAccess::maReadWrite, bm) )
{
unsigned int* data = (unsigned int*)bm.Data;
// i.e. 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);
}