最初のビットマップはキャンバス全体を埋めるように設定されています。Androidで2つのビットマップを結合する方法
tattoo.buildDrawingCache();
Bitmap bit2 = tattoo.getDrawingCache();
が、私はそれが他のビットマップに同じスケール、回転、翻訳親戚の維持他の上にこのビットマップを追加したい:私はその後、使ってImageViewのから作成された別のビットマップを追加します。私の問題は、スケールと回転がうまくいくように見えますが、平行移動は一方または他方にシフトします。両方の画像が同じ画像が同じ高さと幅を有しているかどうか
public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(bmp1, 0,0 , null);
Matrix matrix = new Matrix();
matrix.setScale(tattoo.getScaleX()/imageView.getScaleX(), tattoo.getScaleY()/imageView.getScaleY());
int[] tattooCoords = getRelativeCoords(tattoo);
int[] imageViewCoords = getRelativeCoords(imageView);
matrix.setTranslate(tattooCoords[0] - imageViewCoords[0], tattooCoords[1] - imageViewCoords[1]);
matrix.postRotate(tattoo.getRotation(), tattoo.getX() + tattoo.getWidth()/2,
tattoo.getY() + tattoo.getHeight()/2);
canvas.drawBitmap(bmp2, matrix, null);
bmp1.recycle();
bmp2.recycle();
return bmOverlay;
}
private static int[] getRelativeCoords(View v){
View parent = v.getRootView();
int[] viewLocation = new int[2];
v.getLocationInWindow(viewLocation);
int[] rootLocation = new int[2];
parent.getLocationInWindow(rootLocation);
int relativeLeft = viewLocation[0] - rootLocation[0];
int relativeTop = viewLocation[1] - rootLocation[1];
return new int[]{relativeLeft, relativeTop};
}