4

该类在 FMX (FireMonkey) 中FMX.Types.TBitmap具有该ScanLine属性,但似乎该属性已被删除,并且在 FMX2 (FireMonkey FM2) 中缺失。

有什么解决方法吗?我们应该如何TBitmap直接在 FMX2 中访问内容?

4

2 回答 2

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;
于 2013-03-03T12:18:20.240 回答
1

这是 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);
}
于 2013-03-27T02:58:33.897 回答