I have a variable Bitmap image
. I have imageButton
in my fragment. I can change image of imageButton
with Glide.with().load().into()
. But I want not to just change image but to save it into Bitmap
variable so I can use it for some other task. I tried this
Bitmap image = Glide.with(getContext()).asBitmap().load(imagePath).submit().get();
imageButton.setImageBitmap(image);
But image of imageButton does not change. What's wrong with first line then? Because I am pretty sure that problem is there but don't understand yet what is exactly wrong.
A solution is to do
Bitmap image = BitmapFactory.
decodeStream(getContext().
getContentResolver().
openInputStream(selectedImage));
imageButton.setImageBitmap(image);
Where selectedImage
is Uri selectedImage = data.getData()
of onActivityResult
method, but it will be total mess because of size of bitmap, so we have to use createScaledBitmap
, I don't like it. For some reason Bitmap image = BitmapFactory.decodeFile(imagePath)
doesn't work, imageButton just becomes tiny grey square, and I didn't find a solution for this.