sandeep
sandeep

Reputation: 947

problem with code to combine two images in android?

i am using the below code for combining two images.

    Bitmap pic = BitmapFactory.decodeResource(getResources(), R.drawable.me);
    Bitmap map = BitmapFactory.decodeResource(getResources(), R.drawable.static);
    Canvas comboImage = new Canvas(map);
    Bitmap out1 = null ;
    comboImage.setBitmap(out1);
    comboImage.drawBitmap(pic, 600, 350, null);

i am assuming that the i can use the bitmap out1 for getting the final image. but 'comboImage.setBitmap(out1);' line is causing a crash. without this line i am not able to see any images. how can i get the final combined image?

Upvotes: 2

Views: 2930

Answers (1)

Matt
Matt

Reputation: 5511

If you want the final image to be out1, you would do it like this:

Bitmap out1 = Bitmap.createBitmap(...);
Canvas comboImage = new Canvas(out1);
comboImage.drawBitmap(map, ...);
comboImage.drawBitmap(pic, ...);

out1 would then be the merge images

Upvotes: 1

Related Questions