2

I'm coding a simple app which takes two images 1)Photo and 2)Filter(Image file) and then Filter will be applied on the photo. But I also want to save the Image in internal storage after the images are overlapped. As you can see in below code, in last second line I created Bitmap Object filteredPhoto so it can be used to save the image but it can't be referenced because of In-convertible types.

There are two ways,

1) Convert LayerDrawable Object to Drawable and later reference it to Bitmap Object (by casting)

2) Convert LayerDrawable directly to Bitmap if possible.

Can anyone explain me how to make this happen?

Note : This question may have been asked by others but none of them has replied them properly. Most of them said use Canvas but I can't find how Canvas can help me in my problem so kindly don't mark my question as Duplicate.

Code :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    theImageViewMID = (ImageView) findViewById(R.id.theImageView_MID);

    Drawable layers[] = new Drawable[2];
    layers[0] = ContextCompat.getDrawable(this, R.drawable.image_1546);
    layers[1] = ContextCompat.getDrawable(this, R.drawable.new_filter);
    layers[1].setAlpha(75);

    LayerDrawable layerDrawable = new LayerDrawable(layers);

    theImageViewMID.setImageDrawable(layerDrawable);

    layerDrawable.set

    Bitmap filteredPhoto = ((BitmapDrawable) LayerDrawable).getBitmap();
    //MediaStore.Images.Media.insertImage(getContentResolver(), filteredPhoto, "THIS IS TITLE", "THIS IS DESCRIPTION");
}
Allan Pereira
  • 2,572
  • 4
  • 21
  • 28
Eddy
  • 344
  • 5
  • 16
  • Your question is a duplicate(with http://stackoverflow.com/questions/3035692/how-to-convert-a-drawable-to-a-bitmap?rq=1 for example), the only difference is you'll not be able to make the conversion with the current code because you're doing it in the onCreate() callback at which points the views haven't been measured and layout yet, so the drawables aren't drawn either . – user Jun 23 '16 at 17:02
  • In code you can see I have made Array Object of Drawable which holds two images and then a LayerDrawable Object below that which is dealing with the Array Object of Drawable. The "new_filter" image is overlapped on the "image_1546" and when I display it the picture seems to be one. Can you tell me if there is a way to save that picture? – Eddy Jun 25 '16 at 07:27

0 Answers0