Android save bmp image -


i'm trying save captured .bmp file sdcard. here fragment of code responsible this:

    string root = environment.getexternalstoragedirectory().tostring();     file mfolder = new file(root + "/mfolder");      if (!mfolder.exists())      {         mfolder.mkdir();     }     string strf = mfolder.getabsolutepath();     file msubfolder = new file(strf + "/myapp-subfolder");      if (!msubfolder.exists())      {         msubfolder.mkdir();     }     string s = "myfile.png";      file f = new file(msubfolder.getabsolutepath(),s);     string strmyimagepath = f.getabsolutepath();     fileoutputstream fos = null;     try      {         fos = new fileoutputstream(f);         bmp.compress(bitmap.compressformat.png,70, fos);          fos.flush();         fos.close();         log.d("asd", "yeah!");     //  mediastore.images.media.insertimage(getcontentresolver(), b, "screen", "screen");     }catch (filenotfoundexception e) {         e.printstacktrace();     } catch (exception e) {         e.printstacktrace();     } } 

but there error:

images invalid , size 0kb

what doing wrong?

try

private boolean savetosd() {          string imagename = null;          bitmap sourcebitmap = ((bitmapdrawable) img.getdrawable()).getbitmap();          boolean imagesaved = false;          if (sourcebitmap != null && !sourcebitmap.isrecycled()) {             file storagepath = new file(                     environment.getexternalstoragedirectory() + "/igridu/");              if (!storagepath.exists()) {                 storagepath.mkdirs();             }              int count = storagepath.list().length;              log.i("savetosd count", "" + count);              imagename = string.valueof(count + 1) + "_igridu";              fileoutputstream out = null;             file imagefile = new file(storagepath, string.format("%s.jpg",                     imagename));             try {                 out = new fileoutputstream(imagefile);                 imagesaved = sourcebitmap.compress(bitmap.compressformat.jpeg,                         90, out);                 out.flush();                 out.close();             } catch (exception e) {                 log.e("savetosd ", "unable write image gallery" + e);              }              contentvalues values = new contentvalues(3);             values.put(images.media.title, imagename);             values.put(images.media.mime_type, "image/jpeg");             values.put("_data", imagefile.getabsolutepath());              getcontentresolver().insert(media.external_content_uri, values);         }          return imagesaved;     } 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -