Picasso无法在本地加载图像
问题描述:
我尝试下载图像并将其保存在本地。一切运行低谷我没有得到任何例外,但文件不出现在我的位置Picasso无法在本地加载图像
我搜索了一个解决方案,但没有找到任何。
继承人我的代码:
private void saveImages() {
try{
final File thumbsPath = new File(getExternalFilesDir(null), "thumbs");
if (!thumbsPath.exists())
thumbsPath.mkdirs();
Target target = new Target(){
@Override
public void onBitmapLoaded(final Bitmap bitmap, Picasso.LoadedFrom from) {
new Thread(new Runnable() {
@Override
public void run() {
File file = new File(thumbsPath.getAbsolutePath() + "/file.jpeg"); //folder exists
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, ostream);
ostream.flush();
ostream.close();
} catch (Exception e) {
Log.e("ERROR", e.getMessage());
}
}
}).start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
Log.e("ERROR", "");
}
@Override
public void onPrepareLoad(Drawable placeHolderDrawable) {
Log.e("ERROR", "");
}
};
Picasso.with(getApplicationContext())
.load(myurltodownloadfrom)
.into(target);
}
catch (Exception e){
Log.e("ERROR",e.getMessage());
}
}
对不起,我使用最终的文件thumbsPath = new File(getExternalFilesDir(null),“thumbs”); File file = new File(thumbsPath.getAbsolutePath()+“/file.jpeg”);为了节省。我想这可能会更好理解 – tolik