Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

java - how to merge to two bitmap one over another

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 Bitmap combineImages(Bitmap ScaledBitmap, Bitmap bit) {

        int X = bit.getWidth();
        int Y = bit.getHeight();

        Scaled_X = ScaledBitmap.getWidth();
        scaled_Y = ScaledBitmap.getHeight();

        System.out.println("Combined Images");

        System.out.println("Bit :" + X + "/t" + Y);

        System.out.println("SCaled_Bitmap :" + Scaled_X + "" + scaled_Y);

        overlaybitmap = Bitmap.createBitmap(ScaledBitmap.getWidth(),
                ScaledBitmap.getHeight(), ScaledBitmap.getConfig());
        Canvas canvas = new Canvas(overlaybitmap);
        canvas.drawBitmap(ScaledBitmap, new Matrix(), null);
        canvas.drawBitmap(bit, new Matrix(), null);

        return overlaybitmap;
    }

Any help would be greatly appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);
    bmp1.recycle();
    bmp2.recycle();
    return bmOverlay;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...