multiple images in a one single image

2019-04-01 22:04发布

问题:

I want to create a bitmap / image which has many images like "Collage" which has more then one images in a single picture.

I have stored all my images in a grid view but now i want to create a single image from all those images. And even i want to make few images click able

so what can be the road map to do this ? any sort of help / example will be helpful.

reference image

回答1:

    Bitmap pic1 = BitmapFactory.decodeResource(getResources(), R.drawable.pic1);    
    Bitmap pic2 = BitmapFactory.decodeResource(getResources(), R.drawable.pic2);      
    Bitmap bg= BitmapFactory.decodeResource(getResources(), R.drawable.background);
    Bitmap out1 = Bitmap.createBitmap(bg) ;        
    Canvas comboImage = new Canvas(out1);
    comboImage.drawBitmap(pic1, 10f, 20f, null); 
    comboImage.drawBitmap(pic2, 30f, 40f, null); 

out1 will have pic1 & pic2, with a background image bg.



回答2:

To create a single image from multiple images look at using Canvas. You can put bitmaps (and drawables) on a canvas. You can commit the changes and then push then to a single bitmap that you can then use. As far as making certain sections clickable after making it one single image, I will leave this up to someone else to explain, I am not worked directly with the ontouch() functions.