问题
this is my activity in i am receiving bitmap and making multiple bitmap and show in one image view i m getting multiple image but not set properly in image view please help me ?
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;
}}
回答1:
you can do something like the following :
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;
}
you call this method like the following :
ImageView myImageView = (ImageView) findViewById(R.id.myImageView);
Bitmap bitmap = ((BitmapDrawable) myImageView.getDrawable())
.getBitmap();
Bitmap b = drawMultipleBitmapsOnImageView(bitmap);
myImageView.setImageBitmap(b);
and please give me some feedback .
Hope that helps .
回答2:
You can draw everything like it was already said, or you can create a LayerDrawable with those BitmapDrawables. It is easier and consumes less memory, so if you can achieve what you want with this, do it.
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());
来源:https://stackoverflow.com/questions/21601025/unable-to-set-multiple-bitmap-in-one-imageview