how to merge to two bitmap one over another

后端 未结 2 1948
我在风中等你
我在风中等你 2020-12-02 23:27

I have two images and i want to save one bitmap image over another exactly at the same point where it is present i also move image using gesture .

public Bi         


        
相关标签:
2条回答
  • 2020-12-02 23:55

    you can combine two bitmaps i.e a bitmap on another bitmap as an overlay
    try this below code:

     public Bitmap bitmapOverlayToCenter(Bitmap bitmap1, Bitmap overlayBitmap) {
            int bitmap1Width = bitmap1.getWidth();
            int bitmap1Height = bitmap1.getHeight();
            int bitmap2Width = overlayBitmap.getWidth();
            int bitmap2Height = overlayBitmap.getHeight();
    
            float marginLeft = (float) (bitmap1Width * 0.5 - bitmap2Width * 0.5);
            float marginTop = (float) (bitmap1Height * 0.5 - bitmap2Height * 0.5);
    
            Bitmap finalBitmap = Bitmap.createBitmap(bitmap1Width, bitmap1Height, bitmap1.getConfig());
            Canvas canvas = new Canvas(finalBitmap);
            canvas.drawBitmap(bitmap1, new Matrix(), null);
            canvas.drawBitmap(overlayBitmap, marginLeft, marginTop, null);
            return finalBitmap;
        }  
    
    0 讨论(0)
  • 2020-12-03 00:05

    you can combine two bitmaps like this

    public static Bitmap overlay(Bitmap bmp1, Bitmap bmp2) {
        Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig());
        Canvas canvas = new Canvas(bmOverlay);
        canvas.drawBitmap(bmp1, new Matrix(), null);
        canvas.drawBitmap(bmp2, 0, 0, null);
        return bmOverlay;
    }
    
    0 讨论(0)
提交回复
热议问题