0
我嘗試下載圖像並將其保存在本地。一切運行低谷我沒有得到任何例外,但文件不出現在我的位置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