//save image
public static void imageDownload(Context ctx, String url){
Picasso.with(ctx)
.load("http://blog.concretesolutions.com.br/wp-content/uploads/2015/04/Android1.png")
.into(getTarget(url));
}
//target to save
private static Target getTarget(final String url){
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(Environment.getExternalStorageDirectory().getPath() + "/" + url);
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, ostream);
ostream.flush();
ostream.close();
} catch (IOException e) {
Log.e("IOException", e.getLocalizedMessage());
}
}
}).start();
}
@Override
public void onBitmapFailed(Drawable errorDrawable) {
}
使用上面的代碼保存的位圖外部存儲..Please確保您的動態權限和清單文件已經建立properly.Please按照此討論Saving image from url using Picasso?
如果你想將它保存到特定的文件夾,然後使用_Target_回調用於picasso這將返回位圖,您可以將該位圖保存到特定文件夾 – Piyush
我也使用回調,但我不知道從哪裏我可以得到ima GE。 – Mehul
在_onBitmapLoaded_方法中,您可以獲取位圖,這將是您的圖像。 – Piyush