Poor quality image when restart the application - android

In the app there is an item add an avatar in your account, when you add it - the picture is filled to the server and displayed as expected:
Good
But if i do restart the application, then image quality is lost:
Bad
When comparing the weight and size of the image between what was covered on the original server and all is fine, the weight and size is identical. Displaying an avatar comes directly from the server. What could be the problem?
Caching is missing, use Picasso. Code to display avatars:
Picasso.with(context).load(link).into(imageview);

maybe if you call
Picasso.with (context)
.load (link)
.fit()
.into(imageView);
it works

Related

How to display images from URL efficently

I need to display a list of images in my application, and i get those images from an API call as an URL. Now I'm using Glide to show them, but i don't like the loading effect it makes (blank space while loading, and the the image). Is there any way to instant show those images, without any loading time and possibly without downloading them?
Since the images are stored on a remote server there is no way to bypass the downloading process, however Glide makes sure to only download the image from remote server when necessary, as the docs state
By default, Glide checks multiple layers of caches before starting a
new request for an image:
Active resources - Is this image displayed in another View right now?
Memory cache - Was this image recently loaded and still in memory?
Resource - Has this image been decoded, transformed, and written to
the disk cache before? Data - Was the data this image was obtained
from written to the disk cache before? The first two steps check to
see if the resource is in memory and if so, return the image
immediately. The second two steps check to see if the image is on disk
and return quickly, but asynchronously.
If all four steps fail to find the image, then Glide will go back to
the original source to retrieve the data (the original File, Uri, Url
etc).
To resolve this,
but i don't like the loading effect it makes (blank space while
loading, and the the image)
You can instead add a default placeholder on the ImageView until the real image is downloaded. This will display a default image while your actual image is downloading and then after download completion will replace it with the actual one.
Glide
.with(context)
.load(url)
.placeholder(R.drawable.ic_placeholder) //your default placeholder resource
.into(imageView)
you can display images from url by two ways:
Without any third party library:
URL url = new URL("URL of image here");
Bitmap bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bitmap);
Second way is by using Picasso

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

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);

Reducing Image Size at Runtime for Android app

I am parsing a json schema which contains textual info and image urls for my android app. I want to read all the images from the schema and then show them in the gallery view of my android app.
But the problem is, the image urls contain HD pics and it takes a lot of time to load. Is there a way I can reduce the size of those images at run time and then display or can you suggest any improvement tip so that the images could load quickly from the schema?
Thanks
Try using Picasso library, it can resize your images whatever you like and bind it to ImageView. See also my answer here.
But if your images on your server are too big, it all depends on your internet connection, how fast they get to your device.
You can resize your image downloaded from url using picasso library. Also it will allow lazy loading of images and you can also set placeholder and error images in your imageview.
You can read complete documentation here: http://square.github.io/picasso/
Picasso.with(context)
.load(url)
.resize(50, 50)// resizing images
.centerCrop()
.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.

Android: recover an image which it has been loaded

I want to load and scale an image from an URL in a imageView.
Then, when user touch that image, I want to load the image (without scale) in other imageView or webView for example.
The problem is that I don't want load image twice. The first time, it download in somewhere (cache?) and I want recover for not doing two request...
some example? suggestion?
thanks
you should consider to load first just a thumbnail of the image and wait with downloading the real one until the user really wants to see it.
for caching see LruChache
This tutorial should help with caching: http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-images/
If you have lots of images, consider using an LruCache. It helps manage large amounts of cache data.

Categories

Resources