Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove image set by Glide and use imageView.setImageBitmap()

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

like image 230
Nilabja Avatar asked Feb 17 '17 06:02

Nilabja


Video Answer


1 Answers

Use:

Glide.with(iv_logo.context)
    .clear(iv_logo);
like image 53
CatalystNZ Avatar answered Oct 09 '22 23:10

CatalystNZ