java - Having an error when saving imageview width and height must be > 0 -


i want save imageview sd card following exception (some times not always) when try bitmap imageview. can please me? in advance

caused by: java.lang.illegalargumentexception: width , height must > 0 @ android.graphics.bitmap.createbitmap(bitmap.java:922) 

public static class saveimagetosd extends asynctask<string, void, string> {      context context;     imageview mimageview;     progressdialog progressdialog;      public saveimagetosd(context context, imageview iv, string name) {         this.context = context;         this.mimageview = iv;     }      @override     protected void onpreexecute() {         progressdialog = progressdialog.show(context, "", context.getresources().getstring(r.string.please_wait), true);     }      @override     protected void onpostexecute(string result) {      }      @override     protected string doinbackground(string... x) {          file projectfolder = new file(environment.getexternalstoragedirectory() + file.separator + settings.projectfolder + file.separator);         boolean foldercreatesuccess = true;         if (!projectfolder.exists()) {             foldercreatesuccess = projectfolder.mkdir();         }         if (foldercreatesuccess) {             bitmap bitmap;             // exception in if statement             if (mimageview.getdrawable() instanceof bitmapdrawable) {                 bitmap = ((bitmapdrawable) mimageview.getdrawable()).getbitmap();             } else {                 drawable d = mimageview.getdrawable();                 bitmap = bitmap.createbitmap(d.getintrinsicwidth(), d.getintrinsicheight(), bitmap.config.argb_8888);                 canvas canvas = new canvas(bitmap);                 d.draw(canvas);             }             file image = new file(projectfolder, "ge_" + system.currenttimemillis() + ".jpg");             boolean success = false;              // encode file png image.             fileoutputstream outstream;             try {                  outstream = new fileoutputstream(image);                 bitmap.compress(bitmap.compressformat.png, 100, outstream);             /* 100 keep full quality of image */                  outstream.flush();                 outstream.close();                 contentvalues values = new contentvalues();                 values.put(mediastore.images.media.title, "title");                 values.put(mediastore.images.media.description, "description");                 values.put(mediastore.images.media.date_taken, system.currenttimemillis());                 values.put(mediastore.images.imagecolumns.bucket_id, image.tostring().tolowercase(locale.us).hashcode());                 values.put(mediastore.images.imagecolumns.bucket_display_name, image.getname().tolowercase(locale.us));                 values.put("_data", image.getabsolutepath());                  contentresolver cr = context.getcontentresolver();                 cr.insert(mediastore.images.media.external_content_uri, values);                 success = true;             } catch (filenotfoundexception e) {                 e.printstacktrace();             } catch (exception e) {                 e.printstacktrace();             }             progressdialog.dismiss();             if (success) {                 ((actionbaractivity)context).runonuithread(new runnable() {                     public void run() {                         toast.maketext(context, context.getresources().getstring(r.string.image_successfully_saved), toast.length_short).show();                     }                 });              } else {                 ((actionbaractivity)context).runonuithread(new runnable() {                     public void run() {                         toast.maketext(context, context.getresources().getstring(r.string.image_successfully_saved), toast.length_short).show();                     }                 });             }          } else {             log.i("create folder", "error during create folder");         }         return "";     } } 

to set image use following code, i'm using transparentdrawable because of picasso wrap content problem

transparentdrawable.setbounds(new rect(0, 0, 1000, 1000)); picasso.with(mcontext).load(((fbphotocard) mimagecards.get(position)).getthumbnail()).placeholder(transparentdrawable).nofade().into(holder.imageview); 

i think exception of because d.getintrinsicwidth(), d.getintrinsicheight() @ line bitmap = bitmap.createbitmap(d.getintrinsicwidth(), d.getintrinsicheight(), bitmap.config.argb_8888);

according android docs drawable.getintrinsicwidth() return intrinsic width of underlying drawable object. returns -1 if has no intrinsic width, such solid color. make sure pass values greater 1 bitmap.createbitmap() method


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -