Android merge two images

前端 未结 2 1466
余生分开走
余生分开走 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);
      

提交回复
热议问题