(1) In order to adapt to a variety of screen size of mobile phones, we create images in accordance with the user's mobile phone screen width and height of the creation.
(2) The software will save the graphics to SDcard, before saving, you need to detect the existence of sdcard, whether writable. If you pass the above check, save the image.
First, we should detect the state of the sdcard and, if not writable, give the hint:
Public voidSavebitmap () {String State=environment.getexternalstoragestate (); if(Environment.MEDIA_MOUNTED.equals (state)) {Savetosdcard (); } Else if(Environment.MEDIA_MOUNTED_READ_ONLY.equals (state)) {Toast.maketext ( This. Context, Getresources (). getString (R.string. tip_sdcard_is_read_only), Toast.length_long). Show (); } Else{Toast.maketext ( This. Context, Getresources (). getString (R.string. tip_sdcard_is_not_available), Toast.length_long). Show (); } }
When SDcard is present and writable, we save the image to the SD card:
Private voidSavetosdcard () {File Sdcard_path=environment.getexternalstoragedirectory (); String Myfloder=getresources (). getString (R.string. Folder_name_in_sdcard); File Paintpad=NewFile (Sdcard_path +"/"+ Myfloder +"/"); Try { if(!paintpad.exists ()) {Paintpad.mkdirs (); } } Catch(Exception e) {e.printstacktrace (); } String TimeStamp= (Dateformat.format ("yyyy. MM.DD.HH.MM.SS", Newjava.util.Date ())). ToString (); String Suffixname=". PNG"; String FullPath=""; FullPath= Sdcard_path +"/"+ Myfloder +"/"+ TimeStamp +Suffixname; Try{Toast.maketext ( This. Context, Getresources (). getString (R.string. tip_save_to) +FullPath, Toast.length_long). Show (); Bitmap.compress (Bitmap.CompressFormat.PNG, -, NewFileOutputStream (FullPath)); } Catch(FileNotFoundException e) {Toast.maketext ( This. Context, Getresources (). getString (R.string. tip_sava_failed)+FullPath, Toast.length_long). Show (); E.printstacktrace (); } }
Save image of Android board