title: Android merge two images
body: <p>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: java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor. Thanks.</p>
  
  <pre><code>        Bitmap bottomImage = BitmapFactory.decodeResource(getResources(),R.drawable.blink);
          Bitmap topImage = (Bitmap) data.getExtras().get("data");  
  
          // As described by Steve Pomeroy in a previous comment, 
          // use the canvas to combine them.
          // Start with the first in the constructor..
          Canvas comboImage = new Canvas(bottomImage);
          // Then draw the second on top of that
          comboImage.drawBitmap(topImage, 0f, 0f, null);
  
          // bottomImage is now a composite of the two. 
  
          // To write the file out to the SDCard:
          OutputStream os = null;
  
          try {
              os = new FileOutputStream("/sdcard/DCIM/Camera/" + "myNewFileName.png");
              bottomImage.compress(CompressFormat.PNG, 50, os);
  
              //Bitmap image.compress(CompressFormat.PNG, 50, os);
          } catch(IOException e) {
              Log.v("error saving","error saving");
              e.printStackTrace();
          }
  </code></pre>
  
  <p>Managed to fix it by simply doing this change:</p>
  
  <pre><code>        int w = bottomImage.getWidth();
          int h = bottomImage.getHeight(); 
          Bitmap new_image = Bitmap.createBitmap(w, h ,bottomImage.getConfig());
  </code></pre>
  
  <p>The problem now is that it doesn't saves the image. Do you know why?</p>