Первый битмап установлен, чтобы заполнить весь холст. Затем я добавить еще один точечный рисунок, который был создан из ImageView с помощью:Как объединить два растровых изображения в Android
tattoo.buildDrawingCache();
Bitmap bit2 = tattoo.getDrawingCache();
Затем я хочу, чтобы добавить растровое изображение поверх другого держать это же масштаб, поворот и перевод относительно другого растрового изображения. Моя проблема в том, что, хотя масштаб и поворот кажутся прекрасными, перевод сдвигается в одну сторону или другую.
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};
}