c# - Saving Bitmap to File - Xamarin, Monodroid -


i trying save bitmap image directory (gallery) inside phone. app being developed in xamarin code c#.

i cant seem figure out how make directory, , save bitmap. suggestions?

public void createbitmap(view view){      view.drawingcacheenabled = true;      view.builddrawingcache (true);      bitmap m_bitmap = view.getdrawingcache(true);      string storagepath = android.os.environment.externalstoragedirectory.absolutepath;     java.io.file storagedirectory = new java.io.file(storagepath);     //storagedirectory.mkdirs ();       //save bitmap     //memorystream stream = new memorystream ();     //m_bitmap.compress (bitmap.compressformat.png, 100, stream);     //stream.close();       try{          string filepath = storagedirectory.tostring() + "appname.png";         fileoutputstream fos = new fileoutputstream (filepath);         bufferedoutputstream bos = new bufferedoutputstream(fos);         m_bitmap.compress (bitmap.compressformat.png, 100, bos);         bos.flush();         bos.close();     } catch (java.io.filenotfoundexception e) {         system.console.writeline ("filenotfound");     } catch (java.io.ioexception e) {         system.console.writeline ("ioexception");     } 

this here slim way export bitmap png-file sd-card using c# stuff:

void exportbitmapaspng(bitmap bitmap) {     var sdcardpath = android.os.environment.externalstoragedirectory.absolutepath;     var filepath = system.io.path.combine(sdcardpath, "test.png");     var stream = new filestream(filepath, filemode.create);     bitmap.compress(bitmap.compressformat.png, 100, stream);     stream.close(); } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -