I'm loading an image from a file. It's a photo gallery so I don't want the image resolution to be scaled down. I've found this code snippet that seems to work great on my devices but I've had users complain about low res images before (That I've been unable to replicate but have confirmed they're real issues) so I want to play it safe.
Will this code snippet load the full resolution image or does it require more than this?
File pageFile = getPageFile();
Glide.with(mPhotoView).load(pageFile)
.apply(new RequestOptions()
.override(Target.SIZE_ORIGINAL))
.into(mPhotoView);
For clarity:
Previously, we were creating our own bitmap from the file input stream and applying it like this:
Glide.with(mPhotoView).load(bitmap).into(mImageView);
This is when users started complaining about image resolution
Please try below:-
Glide.with(imageView).load(url)
.apply(new RequestOptions()
.fitCenter()
.format(DecodeFormat.PREFER_ARGB_8888)
.override(Target.SIZE_ORIGINAL))
.into(imageView);
Also, add this android:adjustViewBounds="true" to your ImageView in XML.
You can use centerCrop() instead of fitCenter() to scale. If used centerCrop(), it scales the image so that it fills the requested bounds and then crops the extra.
I just want to know how to display the image from an URL by using a bitmap and an AsyncTask in a Fragment - not in an Activity.
Use the Piccaso for load image more faster
Picasso.with(context)
.load(image url here)
.resize(50, 50)
.centerCrop()
.into(imageView)
refer this link
hope this helps.
I'm using Glide to download and display images in my gridview. When I click on a item in my gridview I want to display this image in another activity to get this image in full screen. But with Glide I don't know how I can get the image saved in the cache.
Save the image filename in a Database and call again the link to download the image full size with Glide ?
Or try to get the image in the cache but I don't know how to do that.
Could you help me ?
try this code, it's working for me:
On your adapter:
Glide.with(context)
.load("photo_url")
.diskCacheStrategy(DiskCacheStrategy.ALL) //use this to cache
.centerCrop()
.crossFade()
.into(yourImageView);
On your another Activity:
Glide.with(AnotherActivity.this)
.load("photo_url")
.diskCacheStrategy(DiskCacheStrategy.ALL) //use this to cache
.crossFade()
.into(yourImageView);
Use .diskCacheStrategy(DiskCacheStrategy.ALL) to cache & don't forget to make image scaling same. It will working.
Glide not loading image from memory at the first time when rotating (orientation change), and after that it is loading from memory.
I have tried to increase the memory size, the bitmap pool size, all kinds of caching strategies... nothing seemed to work...
I have attached a video.
https://youtu.be/szDnAGxrJLU
Thanks!
.dontAnimate() adding this to Glide solved my problem
Glide.with(view.getContext())
.load(url)
.placeholder(placeholder_image_crop))
.dontAnimate()
.into(view)
You may face this issue because of
CircleImageView/CircularImageView/RoundedImageView are known to have issues with TransitionDrawable (.crossFade() with .thumbnail() or .placeholder()) and animated GIFs, use a BitmapTransformation (.circleCrop() will be available in v4) or .dontAnimate() to fix the issue.
for more queries refer following links it may help you.
link 1 and link 2
Your ImageViews don't have the exact same size in portrait and in landscape and you are probably using fitCenter() or centerCrop() to resize the image to the ImageView size. When you change orientation, Glide loads the full-sized image from cache but it has to resize it on a background thread first before display, that's why you see a delay after the first orientation change. After resized images for both portrait and landscape are in the memory cache, there is no more delay.
Just to emphasize what is written above and add a solution.
It is possible to change the disk caching strategy to cache the source image but not the memory caching strategy, in that case it will not hit unless it is the same size.
What i did was use .override(width,height) in order to override this strategy and keep the source image in the memory cache.
Glide.with(context)
.load(imgUrl)
.crossFade()
.override(imageWidth,imageHeight)
.into(imgView);
To load image from cache you can pass DiskCacheStrategy.SOURCE to load images from cache.
You can use glide like below and keep don't animate method as it helps to load images in adapter without updating full list. For more check this
Glide.with(context)
.load(row_object.getImage())
.dontAnimate() // will load image
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
.placeholder(ContextCompat.getDrawable(context,
R.mipmap.ic_user_placeholder_50dp))
.into(holder.rowIvPostUserIcon);
This code help me:
Glide.with(view.getContext())
.load(url)
.placeholder(AppCompatResources.getDrawable(view.getContext(), R.drawable.vector_placeholder_vendor_image_crop))
.dontAnimate()
.into(view);
//need add .dontAnimate()
For more information:
https://github.com/bumptech/glide/issues/1026#issuecomment-191709837
First Time glide is unable to load image on custom view like circular Imageview.you Can use error to load image on first time.
The following snippet should help you:
Glide.with(context)
.load(imgUrl)
.crossFade()
.override(imageWidth,imageHeight).error(R.drawable.yourdrawable)
.into(imgView);
Currently I have a Main Activity which has a Fragment loaded into it with a RecyclerView. In the RecyclerView adapter I use Picasso to load in images from the user's gallery based on a stored URI string I have like so:
Picasso.with(context)
.load(imageUri)
.resize(400, 400)
.into(viewHolder.imageView);
When the user clicks on one of these items in the RecyclerView I go to a new Activity and inside its own Fragment onCreateView I load the same image again but size it slightly larger (as the ImageView I'm loading it into is larger size)
Picasso.with(getActivity())
.load(imageUri)
.resize(600, 600)
.centerCrop()
.into(imageView);
My question is...Assuming these images can be quite large...
Is there a better way to load in this image once at say 600px X 600px back when the RecyclerView first needs them, and then reuse the bitmap data in the subsequent Activities and Fragments which need it without reloading again?
I'm open to using a different image loader like Volley if that's better.
Any help would be appreciated.
Marco
You could try Glide it has almost the same api. Instead of Picasso glide has own cache implementation, when Picasso just use http cache and it's hard to control. In glide you need to specify diskCacheStrategy.ALL to make glide cache all you want. Here is cache wiki