开发者

problem with code to combine two images in android?

开发者 https://www.devze.com 2023-03-10 00:06 出处:网络
i am using the below code for combining two images. Bitmap pic = BitmapFactory.decodeResource(getResources(), R.drawable.me);

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 开发者_JAVA技巧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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号