I am trying to write an application, that would allow me to render multiple images onto an ImageView in Android. I can find the method to populate it with a sigle bitmap. Bu
I wrote this method to merge small bitmaps together. It isn't terribly efficient but for simple application purposes it seems to work fine. This example simply centers the overlay image on the base image.
public static Bitmap mergeImage(Bitmap base, Bitmap overlay)
{
int adWDelta = (int)(base.getWidth() - overlay.getWidth())/2 ;
int adHDelta = (int)(base.getHeight() - overlay.getHeight())/2;
Bitmap mBitmap = Bitmap.createBitmap(base.getWidth(), base.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(mBitmap);
canvas.drawBitmap(base, 0, 0, null);
canvas.drawBitmap(overlay, adWDelta, adHDelta, null);
return mBitmap;
}
What are you really trying to accomplish here?
If you are trying to write a game, consider SurfaceView
.
If you are trying to have multiple images appear stacked on top of each other, consider FrameLayout
.
Otherwise, you will have to find a third-party JAR that will allow you to combine your images outside of Android, then put the combined image in your ImageView
.
You can try to create one single bitmap from the multiple images.
You can try to do it with the raw data, by extracting the pixel data from the images as 32-bit int ARGB pixel arrays, merge in one big array, and create a new Bitmap, using the methods of the Bitmap class like copyPixelsToBuffer(), createBitmap() and setPixels().
I think you can also do it by using directly compressed format data and streams and the methods of the BitmapFactory class like decodeByteArray().
If you aren't using too many images at once you can use separate ImageViews and recycle them/reload the resources. I had a pretty rough experience with something like that recently, but it can be done.
Good luck.