Android Bitmap Combine combineDrawables(Resources resources, int head, int body, int legs)

Here you can find the source of combineDrawables(Resources resources, int head, int body, int legs)

Description

combine Drawables

Declaration

public static Bitmap combineDrawables(Resources resources, int head,
            int body, int legs) 

Method Source Code

//package com.java2s;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;

public class Main {
    public static Bitmap combineDrawables(Resources resources, int head,
            int body, int legs) {
        Bitmap headBitmap = getBitmap(resources, head);
        Bitmap bodyBitmap = getBitmap(resources, body);
        Bitmap legsBitmap = getBitmap(resources, legs);

        int height = headBitmap.getHeight() + bodyBitmap.getHeight()
                + legsBitmap.getHeight();
        int width = Math.max(headBitmap.getWidth(),
                Math.max(bodyBitmap.getWidth(), legsBitmap.getWidth()));

        Bitmap result = Bitmap.createBitmap(width, height,
                Bitmap.Config.ARGB_8888);
        Canvas comboImage = new Canvas(result);
        comboImage.drawBitmap(headBitmap, 0f, 0f, null);
        comboImage.drawBitmap(bodyBitmap, 0f, headBitmap.getHeight(), null);
        comboImage.drawBitmap(legsBitmap, 0f, headBitmap.getHeight()
                + bodyBitmap.getHeight(), null);

        return result;
    }//from   w  w w. j  av a2  s  . c  o m

    public static Bitmap getBitmap(Resources resources,
            int drawableResourceId) {
        return BitmapFactory.decodeResource(resources, drawableResourceId);
    }
}

Related

  1. combineImages(Bitmap c, Bitmap s)
  2. merge(Bitmap bmp1, Bitmap bmp2)