这是我的活动,我正在接收位图并制作多个位图并在一个图像视图中显示 我在图像视图中获取多张图像但未正确设置请帮助我?
private Bitmap Final_Murge_Bitmap()
{
Murge_Bitmap = null;
try {
Murge_Bitmap = Bitmap.createBitmap(500, 500, Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(Murge_Bitmap);
c.drawBitmap(Murge_Bitmap, 0, 0, null);
Drawable drawable1 = new BitmapDrawable(Bitmap_recieve);
Drawable drawable2 = new BitmapDrawable(Bitmap_recieve);
Drawable drawable3 = new BitmapDrawable(Bitmap_recieve);
Drawable drawable4 = new BitmapDrawable(Bitmap_recieve);
Drawable drawable5 = new BitmapDrawable(Bitmap_recieve);
Drawable drawable6 = new BitmapDrawable(Bitmap_recieve);
Drawable drawable7 = new BitmapDrawable(Bitmap_recieve);
Drawable drawable8 = new BitmapDrawable(Bitmap_recieve);
drawable1.setBounds(220, 220, 501, 501);
drawable2.setBounds(330, 330, 400, 400);
drawable3.setBounds(160, 150, 200, 200);
drawable4.setBounds(140, 120, 200, 200);
drawable5.setBounds(120, 100, 400, 400);
drawable6.setBounds(100, 80, 500, 500);
drawable7.setBounds(80, 70, 200, 200);
drawable8.setBounds(60, 60, 200, 200);
drawable1.draw(c);
drawable2.draw(c);
drawable3.draw(c);
drawable4.draw(c);
drawable5.draw(c);
drawable6.draw(c);
drawable7.draw(c);
drawable8.draw(c);
} catch (Exception e)
{
}
return Murge_Bitmap;
}}
答案 0 :(得分:1)
您可以执行以下操作:
public Bitmap drawMultipleBitmapsOnImageView(Bitmap b) {
Bitmap drawnBitmap = null;
try {
drawnBitmap = Bitmap.createBitmap(400, 400, Config.ARGB_8888);
Canvas canvas = new Canvas(drawnBitmap);
// JUST CHANGE TO DIFFERENT Bitmaps and coordinates .
canvas.drawBitmap(b, 100, 100, null);
canvas.drawBitmap(b, 200, 300, null);
canvas.drawBitmap(b, 100, 200, null);
canvas.drawBitmap(b, 300, 350, null);
} catch (Exception e) {
e.printStackTrace();
}
return drawnBitmap;
}
您可以像下面这样调用此方法:
ImageView myImageView = (ImageView) findViewById(R.id.myImageView);
Bitmap bitmap = ((BitmapDrawable) myImageView.getDrawable())
.getBitmap();
Bitmap b = drawMultipleBitmapsOnImageView(bitmap);
myImageView.setImageBitmap(b);
请给我一些反馈。
希望有所帮助。
答案 1 :(得分:0)
您可以像已经说过的那样绘制所有内容,也可以使用这些BitmapDrawables创建LayerDrawable。它更容易并且消耗更少的内存,所以如果你可以用它实现你想要的,那就去做吧。
private LayerDrawable createLayerDrawable() {
Drawable layers = new Drawable[4];
layers[0] = murge_drawable; // converted from Murge_Bitmap
layers[1] = drawable1;
layers[2] = drawable2;
layers[3] = drawable3;
// ...
return new LayerDrawable(layers);
}
imageview.setImageDrawable(getLayerDrawable());