I have a fragment where at first an Image is set to an imageView using Glide (image url fetched from internet). Then upon click on the imageview a new image can be chose from either gallery or camera intent. the problem is when I try to set the bitmap that I get from OnActivityResult(). The image actually sets but that is overlapped by glide. I need to show image captured from camera/gallery. Any help is appreciated, also if it can be done using Picasso or any other library please suggest that. Below is what I have tried so far
the onActivityResult ()
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
{
if (requestCode == SELECT_FILE)
onSelectFromGalleryResult(data);
else if (requestCode == REQUEST_CAMERA)
// onCaptureImageResult((Bitmap) data.getExtras().get("data"));
onCaptureImageResult(data);
}
}
private void onCaptureImageResult(Intent data)
{
if (data != null)
{
mImageUri = Uri.parse("file://" + data.getStringExtra(CameraConfiguration.Arguments.FILE_PATH));
}
try
{
bitmap_image = MediaStore.Images.Media.getBitmap(mContext.getContentResolver(), mImageUri);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap_image.compress(Bitmap.CompressFormat.JPEG, 60, bytes);
bitmap_image = Bitmap.createScaledBitmap(bitmap_image, (int) (bitmap_image.getWidth() * 0.5), (int) (bitmap_image.getHeight() * 0.5), true);
ExifInterface ei = new ExifInterface(data.getStringExtra(CameraConfiguration.Arguments.FILE_PATH));
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
switch (orientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
bitmap_image = (SnappyUtils.rotateImage(bitmap_image, 90));
break;
case ExifInterface.ORIENTATION_ROTATE_180:
bitmap_image = (SnappyUtils.rotateImage(bitmap_image, 180));
break;
case ExifInterface.ORIENTATION_ROTATE_270:
bitmap_image = (SnappyUtils.rotateImage(bitmap_image, 270));
break;
case ExifInterface.ORIENTATION_NORMAL:
default:
break;
}
}
catch (IOException e)
{
e.printStackTrace();
Log.d("exception", e.toString());
}
////////////////////// it is showing on iv_logo2 as expected as it does not has anything set by glide//////////////////////////////////////////////////////////////////
iv_logo.setBackground(null);
iv_logo.setImageBitmap(bitmap_image);
iv_logo2.setImageBitmap(bitmap_image);
///////////////////////////tried added this by seeing other SO posts //////////////////////////////////////////////////////////////////
Glide.with(mContext)
.load(mImageUri)
.signature(new StringSignature(String.valueOf(System.currentTimeMillis())))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(iv_logo);
}
Also please note that this is not the same issue as removing cache of Glide
After spending lots of time figuring out how to remove image set by Glide, and failing, decided to go old-school and first download the image in phone and set that image as bitmap in my application
asynchtask to download image
private class GetImages extends AsyncTask<Object, Object, Object>
{
private String requestUrl, imagename_;
private ImageView view;
private Bitmap bitmap;
private FileOutputStream fos;
private GetImages(String requestUrl, ImageView view, String _imagename_)
{
this.requestUrl = requestUrl;
this.view = view;
this.imagename_ = _imagename_;
}
@Override
protected Object doInBackground(Object... objects)
{
try
{
URL url = new URL(requestUrl);
URLConnection conn = url.openConnection();
bitmap = BitmapFactory.decodeStream(conn.getInputStream());
}
catch (Exception ex)
{
ex.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Object o)
{
view.setImageBitmap(bitmap);
}
}