Preciso combinar 2 imagens em uma. Basicamente, tudo o que preciso fazer é sobrepor um deles em cima do outro no centro da imagem. Isso precisa funcionar em todos os principais dispositivos Android.
Eu tentei várias coisas, mas aqui está o meu trecho de código a partir de agora (e sim, eu sei que está uma bagunça, precisamos descobrir delx e dely):
/* Rotate our original photo */
// final float scale = getResources().getDisplayMetrics().density;
canvas.drawBitmap(bmp, 0f, 0f, null);
final float overlay_scale_factor = .5f;
final int overlaywidth = (int)(overlay.getWidth() * overlay_scale_factor);
final int overlayheight = (int)(overlay.getHeight() * overlay_scale_factor);
final int delx = overlaywidth;
final int dely = overlayheight;
Matrix mat = new Matrix();
mat.postRotate(270);
mat.postScale(overlay_scale_factor, overlay_scale_factor);
//mat.postTranslate(-delx, -dely);
canvas.drawBitmap(overlay, mat, null);
/* Bottom image "composite" is now a composite of the two. */
Qualquer ajuda é apreciada. Eu sei que isso é apenas matemática, mas eu não sou bom nesse tipo de coisa.
A primeira imagem, "bmp" é 100% do tamanho da tela. A segunda imagem, "overlay" é a sobreposição que precisa ser centralizada após girar 270 graus.
Respostas:
4 para resposta № 1Totalmente não testado, mas eu esperava que algo assim funcionasse:
// Set the origin (0,0) in the middle of the view
canvas.translate(width/2, height/2);
// Draw the first bitmap so it is centered at (0,0)
canvas.drawBitmap(bmp, -bmp.getWidth()/2, -bmp.getHeight()/2, null);
// Rotate & scale
canvas.save();
canvas.rotate(270);
canvas.scale(.5f);
// Draw the overlay
canvas.drawBitmap(overlay, -overlay.getWidth()/2, -overlay.getHeight()/2, null);
canvas.restore();