merge Two Bitmap With Overlapping - Android Graphics

Android examples for Graphics:Bitmap Combine

Description

merge Two Bitmap With Overlapping

Demo Code

/**//from  w  ww .j av a2 s .  c  o m
 * This file is part of Owlet.
 * 
 * Owlet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * Owlet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *  
 * You should have received a copy of the GNU General Public License
 * along with Owlet.  If not, see <http://www.gnu.org/licenses/>.
 */
//package com.java2s;
import android.graphics.Bitmap;
import android.graphics.Canvas;

public class Main {
    public static Bitmap mergeTwoBitmapWithOverlapping(Bitmap up, Bitmap down) {
        Bitmap cs = null;
        int width, height = 0;
        final Bitmap first = Bitmap.createScaledBitmap(up,
                up.getWidth() / 2, up.getHeight() / 2, true);
        final Bitmap second = Bitmap.createScaledBitmap(down,
                (int) (down.getWidth() / 1.5),
                (int) (down.getHeight() / 1.5), true);
        width = up.getWidth();
        height = up.getHeight();
        cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

        Canvas twiseImage = new Canvas(cs);

        twiseImage.drawBitmap(first, width - (int) (first.getWidth() * 2),
                height - (int) (first.getHeight()), null);
        twiseImage.drawBitmap(second, width - second.getWidth(), 0f, null);

        return cs;
    }
}

Related Tutorials