Picasso is not loading image if I use resize() function - android

When I load a file using picasso with resize option, it doesn't show up. I'm using Picasso.with(mContext).load(file).resize(160,213).into(holder.skinImage);
The file has dimension of 4608 X 3456. It loads up when I use Picasso without resize but it takes too long to load.
Picasso.with(mContext).load(file).into(holder.skinImage);
EDIT: I just tried loading image of size 1080 X 1920 and it worked perfectly.

Strange for me that you say that with no resizing downloading takes more time - it should take exact the same time.
Resizing with Picasso .resize() is bad if you planning to obtain that image anywhere else with no resizing, since it will be cached with some -resize-160,213 prefix and when you will try to obtain it via just URL you'll get cache miss. So why not resize by XML layout argument?
Also you can enable Http logging to see, whats going on under the hood. At least you will see, if it's not downloaded or not placed (and see the cache inside picasso instance - is it picture there or not?). If you find out the second option - try to change layout.

Try to add scaletype like this
Picasso.with(mContext).load(file).resize(160,213).centerCrop().into(holder.skinImage);

Related

Glide takes long time before displaying large images

I am trying to load images (around 5mb each) into ImageView's of size 45x45 dp in a RecyclerView. Even though original image is large, doesn't Glide load a smaller version of it because target ImageView is small? So, I expect Glide to load images in just a few seconds with an average internet speed. But, it takes like 20 seconds. What is the problem?
Images are stored in firebase storage.
Glide code :
Glide.with(context).load(firebaseStorageUrl).into(imageView);
Glide needs to load the full image from the internet before it can resize it. So the download takes a long time the first time. Afterwards it can use the small image from the cahe it created if you have caching activated.
In case you don't want to load smaller files, I recommend using a Gif-drawable library for loading large images from Glide into GifDrawable(works as an ImageView).
It can load files more than 100MB very fast. It works with plain JPG, PNG and BMP too. If these are GIFs, it plays without any delay or freeze.
If drawables declared by android:src and/or android:background are GIF files then they will be automatically recognized as GifDrawables and animated. If given drawable is not a GIF then mentioned Views work like plain ImageView and ImageButton.
Glide downloads the image first, and then you have methods to retrieve the image as bitmap to resize and compress the image. However, that won't solve your problem . Possibly there are two solutions for this:
Keep a low sized image in the server.
Use a File downloader library, which helps to download images serially and asynchronously as a queue, which would help to download the file quick. FileDownloader library is a good option for this.
Use Override in Glide for load image faster.

Picasso Taking time to load images

I'm using picasso to load images in my recycler view adaper but it is taking to much time to load image. Here is my call to load image with picasso.
Picasso.with(hostActivity).load("ImageUrl").fit().centerCrop().into(holder.ImageView);
If I do same thing with asynctask task, image loaded instantly.
Am I doing any thing wrong?
Thanks.
fit() needs to wait for the size of the ImageView to be determined before it can size the image to match, and the size can't be calculated until the end of the layout pass. You might get quicker results by using resize() if you are able to predict reasonable width and height values.
You might also want to look at the Glide library as it takes a different approach to caching that can be quicker than Picasso in some cases, for example instead of caching full size images it caches the resized ones. However, there are many pros and cons to both libraries; although the syntaxes are very similar, some things that work in Picasso will not work in Glide, and vice versa.

Load a very large Image in android

Assumes I have a picture, it very large images or other sets of content where you are only looking at small bits at a time, because you can start seeing your content without having to load it all into memory at once.
In iOs we can use CATiledLayer to repeatedly draw tiles to fill up view’s background
In Android I can see Google Map, It also load each part of map when you scroll but I don't understand what is solution of them.
I want know what is the solution same CATiledLayer in Android or other to load very large Image
you can actually scale down the bitmap according to the size of the image view.
Don't give wrap_content in width and height try to give a relative width and height.
use
ImageView.getheight()
ImageView.getWidth()
get the size and load according to it
see this link
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html#read-bitmap
You can use a library load images efficiently and manage caching them instead of downloading them again. I suggest Picasso or Glide. This tutorial compares between them and explains few features.
I hope it's useful.

which is best? Creating bitmap from imageview or downloading the file

we are using an app for setting wallpaper in android device, for that we are doing below steps
1) we have set of images and URLs
2) We are fetching the URL on an Imageview
so now we have to set the wallpaper, for that we need the image file, which is the best way to do it?
1) Download the file directly from URL and store it in a local storage and use it as wallpaper.
or
2) Create a bitmap from the Imageview and use it as wallpaper.
Doing the second option will reduce any quality of the image we using?
First option how to we can do it?
We have fetch the images successfully inside the application.
Always prefer to cache your image downloads so that you don't have to repeat the task. Using libraries like Picasso or Glide reduces a lot of effort is handling your images while at the same time optimizing your code.
Additionally it's best to use the original image as wallpaper rather than consuming the image view because if you have set any scale type's on your image view then your image will be cropped.
Picasso allows for hassle-free image loading in your application—often in one line of code!
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

Loading big size image in Volley

I want to download some images from the net and show them in an ImageView .So I am using Volley.
How can I reduce the size of the images before showing them in ImageView. The original size of the images are 640 by 640 and I need to use them as an icon. How can I change their size to 64*64.
The question is not related to memory management. I just need to know how can I access the bitmap which I have downloaded from Volley.
The right way:
If you control the server you're requesting images from:
Change the actual image on the server: Create a thumbnail version for your images and use it when appropriate.
If you don't control the server:
Consider creating a service that will do this for you. Something along the lines of:
Ask your image service for an image with a given URL.
Image service checks its cache for a thumbnail version for that URL. If it exists returns it.
Image service retrieves the image, creates a thumbnail version, caches it and returns it to you.
The OK way:
Manipulate the image after it has been downloaded to the device. This isn't optimal but better than nothing. Luckily, Volley provides a built in way to achieve this: simply provide a maxWidth and maxHeight when requesting the image. Something like this (assuming imageLoader is your ImageLoader and imageListener is you listener for this request:
imageLoader.get("http://...", imageListener, maxWidth, maxHeight);
Remember, the full size image will be downloaded to the device with this solution.

Categories

Resources