i want to reuse the cached image~
is there a method to get a bitmap object from a cached image?
Do you mean memory cache? If so, extend LruCache, add the methods you need and pass that when you build your Picasso instance.
e.g. new Picasso.Builder(context).memoryCache(cache).build().
nice to meet you again~ you avatar looks cool~
i found some files in data/data/package name directory / cache / Picasso
what is the files used for? is that cached images ?
Those are the cached images on the disk. You don't have direct access to this, perhaps you could if you wanted to.. There is not a really clear away from Picasso.
i want to read these files to reuse some of them...
no method at all ?
Are you using OkHttp? If so then provide your own OkHttpDownloader that you specify the cache dir. Then access the cache dir from there.
You might be missing the point though. Why do you want to re-access the cached bitmap? Picasso does that automatically for you when you load it.
think this scenario : i use picasso to show a lot of images in a screen. the user want to share one of them to facebook or some other social network , i think i have to get a image file from disk ,then attach the file to an intent to send to diffirent app ...
so i try to find the method which can solve this problem...
if i can get a cached image immediately.... users do not need to wait to download another to disk..
this is a pretty well user experience...
So, you should already have the keys to the bitmap you loaded to show them to the user the first time around. You would need to do the file i/o on a background thread anyway so you can either use Picasso#get(key) to load the bitmap on a background thread and then attach it to the intent.
I am closing this issue as I don't think Picasso needs a change. I think you have the info/data you need to achieve this, with or without Picasso.
ok. I got, thank you so much..
by the way, my app is going to online : )
thanks to Piasso, Picasso is pretty awesome!!
attach some screenshot:
thank you again~
Nice, congrats!
Hi daimajia - Could you please share your solution? I'm also trying to do the same.
@vinodtiwari i think using Picasso.with(context).load(url).get() instead of ...into(target), u can get a Bitmap Object, then u can transform it to a File or other Object
Try this
public static Bitmap getBitmap(Context context, String url)
{
final String CACHE_PATH = context.getCacheDir().getAbsolutePath() + "/picasso-cache/";
File[] files = new File(CACHE_PATH).listFiles();
for (File file:files)
{
String fname= file.getName();
if (fname.contains(".") && fname.substring(fname.lastIndexOf(".")).equals(".0"))
{
try
{
BufferedReader br = new BufferedReader(new FileReader(file));
if (br.readLine().equals(url))
{
String image_path = CACHE_PATH + fname.replace(".0", ".1");
if (new File(image_path).exists())
{
return BitmapFactory.decodeFile(image_path);
}
}
}
catch (FileNotFoundException|IOException e)
{
}
}
}
return null;
}
Thanks @YeYintLwin ! It works!!
Most helpful comment
@vinodtiwari i think using
Picasso.with(context).load(url).get()instead of...into(target), u can get a Bitmap Object, then u can transform it to a File or other Object