Render Two images in ImageView in Android?

后端 未结 3 1210
慢半拍i
慢半拍i 2021-01-06 17:51

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

3条回答
  •  天命终不由人
    2021-01-06 18:12

    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;
    }
    

提交回复
热议问题