Android merge two images

我怕爱的太早我们不能终老 提交于 2019-12-02 07:12:19
Chris

This will help you =)


Edit: (embed answer from link)

the only static "constructor" for Bitmap returning a mutable one is:

(Class: Bitmap) public static Bitmap createBitmap(int width, int height, boolean hasAlpha)
Returns: a mutable bitmap with the specified width and height.

  • So you could work with getPixels/setPixels or like this:

    Bitmap bitmapResult = bm.createBitmap(widthOfOld, heightOfOld, hasAlpha);
    Canvas c = new Canvas();
    c.setDevice(bitmapResult); // drawXY will result on that Bitmap
    c.drawBitmap(bitmapOld, left, top, paint);
    
  • how to get the drawable from Bitmap: by using the BitmapDrawable-Subclass which extends Drawable, like this:

    Bitmap myBitmap = BitmapFactory.decode(path);
    Drawable bd = new BitmapDrawable(myBitmap);
    

The bitmap you are retrieving is immutable, meaning it can't be modified. Although it doesn't specify on the Canvas page that the constructor needs a mutable bitmap, it does.

To create a mutable bitmap, you can use this method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!