2つのImageViewがあります。 ImageView1は背景画像であり、ImageView2はより小さな画像である。 ImageView2の位置は、アプリケーションの途中です。Android:2つのオーバーレイ画像ビューを正しい位置のbmpに結合
ImageView2がImageView1の上にくるように、2つのImageViewをビットマップに結合したいと思います。
結合プロセスは正常に機能しますが、ImageView2は常にbmpファイルの左上隅にあります。
以下は、私は、BMPを生成するために使用される私のコードです:ImageViewsはそれと同じ位置になるよう
ImageView iv = (ImageView)findViewById(R.id.imageView1);
ImageView iv2 = (ImageView)findViewById(R.id.imageView2);
File rootPath = new File(Environment.getExternalStorageDirectory(), "testmerge");
if (!rootPath.exists()) {
rootPath.mkdirs();
}
Toast.makeText(this, rootPath.getPath(), Toast.LENGTH_LONG).show();
File dataFile = new File(rootPath, "picture.png");
iv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
iv.layout(0, 0, iv.getMeasuredWidth(), iv.getMeasuredHeight());
iv.setDrawingCacheEnabled(true);
Bitmap b1 = Bitmap.createBitmap(iv.getDrawingCache());
iv.setDrawingCacheEnabled(false);
iv2.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
iv2.layout(0, 0, iv2.getMeasuredWidth(), iv2.getMeasuredHeight());
iv2.setDrawingCacheEnabled(true);
Bitmap b2 = Bitmap.createBitmap(iv2.getDrawingCache());
iv2.setDrawingCacheEnabled(false);
Bitmap bmOverlay = Bitmap.createBitmap(b1.getWidth(), b1.getHeight(), b1.getConfig());
Canvas canvas = new Canvas(bmOverlay);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawBitmap(b1, 0, 0, null);
canvas.drawBitmap(b2, 0, 0, null);
try {
FileOutputStream out = new FileOutputStream(dataFile, false);
bmOverlay.compress(CompressFormat.PNG, 95, out);
} catch (IOException e) {
e.printStackTrace();
}
あなたはどのように私は、最終的なビットマップファイルの位置を調整することができます教えてもらえますアプリに表示しますか?
ありがとうございました。
@Kintaroはこの回答をどのように達成しましたか? – Erum