[英]Android: Draw a bitmap on top of another, matrix applied
我有一個 imageview,它使用矩陣來縮放/拖動圖像。 現在我想覆蓋另一個圖像。 矩陣變換應應用於背景和疊加的組合。
我確實覆蓋了 onDraw 並使用了
canvas.drawBitmap(overlay, matrix, null);
而疊加是新的疊加,矩陣是當前應用的矩陣。 這工作正常。 不幸的是,我無法指定疊加層應出現在背景頂部的偏移量。 這有效
canvas.drawBitmap(overlay, 50, 10, null);
但是,一旦我再次繪制並縮放背景,覆蓋層仍會保留在 position 上...
如何在繪制應用矩陣的 bitmap 時完成偏移?
問候
您可能需要創建一個適當大小的新 bitmap,您的疊加層將與矩陣變換一起保存。 就像是:
Bitmap overlay2 = Bitmap.createBitmap(....)
Canvas c2 = new Canvas(overlay2);
c2.drawBitmap(overlay, matrix, null);
canvas.drawBitmap(overlay2, 50, 10, null);
另一種可能更好的方法是做 canvas.translate:
canvas.save();
canvas.translate(50,10);
canvas.drawBitmap(overlay, matrix, null);
canvas.restore();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.