How save image in Android Universal Image Loader? -
in lazy-list
use code , image store in folder named lazylist
imageloader imageloader=new imageloader(context); imageloader.displayimage(url, imageview);
but in universal-image-loader
use this
imageloaderconfiguration config = new imageloaderconfiguration.builder(getapplicationcontext()) .build(); imageloader.getinstance().init(config); img = (imageview) this.findviewbyid(r.id.test_id); imageloader imageloader = imageloader.getinstance(); imageloader.displayimage(url.recipe_img_url,img);
but each time use internet image , didn't store image in folder aslo add .diskcache(new unlimiteddisccache(new file("myfolder")))
config
nothing store in myfolder
.any ideas?
you have save image on onloadingcomplete
try , on onloadingcomplete
have save bitmap
variable bitmap
imageloader.getinstance().displayimage(imagepath, imageview, options, new simpleimageloadinglistener() { @override public void onloadingstarted(string imageuri, view view) { spinner.setvisibility(view.visible); } @override public void onloadingfailed(string imageuri, view view, failreason failreason) { string message = null; switch (failreason.gettype()) { case io_error: message = "input/output error"; break; case decoding_error: message = "image can't decoded"; break; case network_denied: message = "downloads denied"; break; case out_of_memory: message = "out of memory error"; break; case unknown: message = "unknown error"; break; } } @override public void onloadingcomplete(string imageuri, view view, bitmap loadedimage) { showedimgae = loadedimage; } });
now onclick on save button / if want save bitmap
/image
sdcard
use
public void downloadimage(){ string root = environment.getexternalstoragedirectory().tostring(); file mydir = new file(root + "/dcim/youfoldername"); mydir.mkdirs(); random generator = new random(); int n = 10000; n = generator.nextint(n); string fname = "imagename-"+ n +".jpg"; file file = new file (mydir, fname); if (file.exists ()) file.delete (); try { fileoutputstream out = new fileoutputstream(file); showedimgae.compress(bitmap.compressformat.jpeg, 100, out); toast.maketext(myactivity.this, "image saved", toast.length_short).show(); out.flush(); out.close(); } catch (exception e) { e.printstacktrace(); } intent mediascanintent = new intent(intent.action_media_scanner_scan_file); uri contenturi = uri.fromfile(file); mediascanintent.setdata(contenturi); getapplicationcontext().sendbroadcast(mediascanintent); }
hope helps you..
Comments
Post a Comment