2017-10-11 31 views
0

enter image description here關於Firemonkey,我該如何組合圖像?

如何在Delphi XE 10.1與FMX上做到這一點?

我正試圖在大圖像上的所需位置插入一個小圖像。 https://forums.embarcadero.com/thread.jspa?messageID=867027 我試過在這個問題中使用一個例子。 在第一個DrawBitmap示例中 如果將Rect座標值設置爲適合所需的座標值,則小圖像將被截斷。 第二個示例沒有在FMX TCanvas中調用Draw的方法。 我想獲得幫助。謝謝。

回答

3

DrawBitmap方法繪製由SrcRect參數描述成由DstRect參數描述的畫布區域縮放的位圖區域。所以你必須使用錯誤的區域矩形。試試這個(它從畫布的左側和頂部8個像素繪製50%的比例位圖):

var 
    Bitmap: TBitmap; 
    SrcRect: TRectF; 
    DstRect: TRectF; 
begin 
    Bitmap := TBitmap.CreateFromFile('C:\MyImage.bmp'); 
    try 
    SrcRect := Bitmap.BoundsF; 

    DstRect := SrcRect; 
    DstRect.Width := DstRect.Width/2; 
    DstRect.Height := DstRect.Height/2; 
    DstRect.Offset(8, 8); 

    Image1.Bitmap.Canvas.BeginScene; 
    Image1.Bitmap.Canvas.DrawBitmap(Bitmap, SrcRect, DstRect, 100); 
    Image1.Bitmap.Canvas.EndScene; 
    finally 
    Bitmap.Free; 
    end; 
end;