我该怎么做?
试
//save image public static voID imageDownload(Context ctx){ Picasso.with(ctx) .load("http://blog.concretesolutions.com.br/wp-content/uploads/2015/04/AndroID1.png") .into(getTarget("http://blog.concretesolutions.com.br/wp-content/uploads/2015/04/AndroID1.png")); } //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() { //Log.i("PRODUTOS_FolDER",CreateAppFolder.getProdutosFolder()); file file = new file(Environment.getExternalStorageDirectory() + url); try { file.createNewfile(); fileOutputStream ostream = new fileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG,100,ostream); ostream.flush(); ostream.close(); } catch (Exception e) { e.printstacktrace(); } } }).start(); } @OverrIDe public voID onBitmapFailed(Drawable errorDrawable) { } @OverrIDe public voID onPrepareLoad(Drawable placeHolderDrawable) { } }; return target; }
例外
java.io.IOException: open Failed: ENOENT (No such file or directory)解决方法 解决了.现在工作正常!
我做了
//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) { } @OverrIDe public voID onPrepareLoad(Drawable placeHolderDrawable) { } }; return target; }总结
以上是内存溢出为你收集整理的android – 使用毕加索从url保存图像?全部内容,希望文章能够帮你解决android – 使用毕加索从url保存图像?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)