How to just download a image by picasso library? - android

I'm using picasso library to download images from URL.What I need is just download the stream not a bitmap, but there is no such method in it.Is it true?
There is :
Picasso.with(this).load(URL_LONG).get(); // return bitmap
Sometimes there are some large images from URL.I need to handle them before displaying for avoiding out of memory.So I cannot load them into bitmap immediately.This is the reason i need the stream.

There is already a feature to provide what you need in Picasso Library. You can actually scale the image when you stream it. Check out this SOF Question.

Related

Why when loading image with Glide as ByteArray into an ImageView doesn't rotate it according to EXIF?

I am using Glide library on Android to load a JPG format image into an ImageView, first I convert it to a ByteArray and then I use the following code:
GlideApp.with(context)
.load(selectedImageByteArray)
.into(image_view)
However, when the selected image orientation EXIF data is equal to "Rotate 270 CW" the image is not rotated by Glide unless I use the following code:
GlideApp.with(context)
.load(selectedImagePath)
.into(image_view)
This way I pass the selected image Uri instead of a ByteArray, why does this happen?
I attach and example (even here in Stack is not rotated):
Because that interface takes a path and nothing else. Kind of annoying since depending on the api level it is not always available. In some of the newer versions of android it is not easy to get the actual path of the file.image
data for that
The short answer is that the data that interface uses is stored in the file, not in the image data itself. There are many stack overflow links about this:
SO

Android Image invalidate in fresco

I am migrating android image caching library from picasso to fresco. I want to know if there is any way to invalidate image already catched as I am adding feature to replace existing image there is way to do so in picasso like
Picasso.with(context).invalidate(URI);
This line remove the cached image and use new one using the url provided which is same like,
http://example.com/image_path
In fresco I have tried using
Fresco.getImagePipeline().evictFromMemoryCache(uri);
This is removing image from view but adding same old cached image again and not getting new one from network as it is working in picasso.
Please refer question Invalidate cache in Picasso The accepted answer doing great in case of picasso.
Fresco.getImagePipeline().evictFromMemoryCache(uri);
Above code line remove the image from the catche but image remains there in the disk and render same if called. We need to remove same image from disk as well. Bellow two lines remove the the image from disc cache also we need to remove the small that is thumbnail image if saved from disk cache.
Fresco.getImagePipelineFactory().getMainDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Fresco.getImagePipelineFactory().getSmallImageDiskStorageCache().remove(new SimpleCacheKey(uri.toString()));
Note: if you are using custom cache key you need to change it that way.
Try this
public static void clearCache(){
//
ImagePipeline imagePipeline = com.facebook.drawee.backends.pipeline.Fresco.getImagePipeline();
imagePipeline.clearMemoryCaches();
imagePipeline.clearDiskCaches();
// combines above two lines
imagePipeline.clearCaches();
}

Using android square's picasso only for caching and decoding

I would like to use Picasso (https://github.com/square/picasso) for caching and bitmap decoding, the problem i'm having is that my request is for a url like for example : server.com/component/1 which gives me a proto file that i parse that contains some other information and a bytestring of the image that i decode to a bitmap.
Is there a way to use picasso for this even thought the request url is not just for an image or just use it for caching and decoding my bitmaps, I've tried using the class Target but it works only with a url of an image alone.
Thanks.
I think it's not possible, what can you do is just caching, load method has only 4 overrides for Uri, String, Bitmap, int. So when you will use Bitmap as a parameter, you will be able to cache your bitmap. Picasso was created only as an image loader, so I don't think that it has method that received all data from the server.

How to get the images from cache when the app is offline by using image loader concept?

I am using universal image loader concept for load the images from remote server and updating to imageview.First time my application having internet connection and saving all the images on application cache("//data//cache/") memory and updating to imageview.Once the images are available in cache I would like to get the images from cache in offline not from remote server.
To get the images i have implemented following universal lazy loading concept:
imageLoader.displayImage(url,imageView, options, animateListener);
I would like to get the same image in offline from cache.
Please give me better solution for get the images in offline loading.
I got the solution as follows:
if(isConnectingToInternet()){
imageLoader.displayImage(image_url, imageView, options);
}
else{
File file = imageLoader.getDiscCache().get(image_url);
Log.v(TAG,"file_ path :"+file.getPath());
Bitmap myBitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
}
you can find Images being handled offline by efficiently using Memory and FileChache, you can view the code as Album Sample this is basically a endless list representation.

How to load image from SD card using Picasso library

i need to load images from the Sd card into gridview.
For efficiency i'm using Picasso Library
Picasso.with(activity).load(images.get(position).getDataPath())
.resize(96, 96).centerCrop().into(viewHolder.image);
I used the following code in the adapter. unfortunately m unable to see any images
so please can any one help.
Note
And also can anyone suggest any efficient image loading library to load the images from the sd card.
Requirement
I dont to load the image every time when scrolling. If it is already loaded dont load the image on scrolling
To load the file you need to convert it to a uri first
Uri uri = Uri.fromFile(new File(images.get(position).getDataPath()));
Picasso.with(activity).load(uri)
.resize(96, 96).centerCrop().into(viewHolder.image);
Requirement I dont to load the image every time when scrolling. If it
is already loaded dont load the image on scrolling
Picasso is excellent for this
In Picasso version 2.5.2, you need to pass a File as argument to load method, so the image can be loaded as:
Picasso.with(context).load(new File(images.get(position).getDataPath()))
.resize(96, 96).centerCrop().into(viewHolder.image);
I didn't want to create a new File because if the path was already obtained from an existing file, there is no need for a new object (want to see the already existing picture in the device).
According to Picasso docs you have to do something like this:
file:///android_asset/DvpvklR.png
So I used to have:
/storage/sdcard/Pictures/findyoursport/yoursport_1482358052384.jpeg
Prepending: file:// did the trick

Categories

Resources