Android merge two images

前端 未结 2 1440
余生分开走
余生分开走 2021-01-25 06:14

I want to merge two images and then save them on the Android SDCard.One is from the camera and one from the resources folder. The problem is that i get this error: Caused by: ja

相关标签:
2条回答
  • 2021-01-25 06:35

    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);
      
    0 讨论(0)
  • 2021-01-25 06:38

    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.

    0 讨论(0)
提交回复
热议问题