<pre name= "code" class= "HTML" ><!--<span style= "font-family:arial, Helvetica, Sans-serif;" > Add </span><span style= in the Androidmainfest.xml file "font-family:arial, Helvetica, Sans-serif;" >--></span>
<!--Create and delete files in SDcard permissions--<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></uses-permission> <!--write data to SDcard permissions--<uses-permission android:name= " Android.permission.WRITE_EXTERNAL_STORAGE "></uses-permission> <uses-permission android:name=" Android.permission.RESTART_PACKAGES "></uses-permission>
<!--<span style= "font-family:arial, Helvetica, Sans-serif;" > Note: Before <application...></application> add </span><span style= "font-family:arial, Helvetica, Sans-serif; " >--></span>
/** * Save Bitmap to a file. Saves the picture to the SD card. * * @param bitmap * @param file * @return error message if the saving is failed. Null if the saving is * successful. * @throws IOException */public static void Savebitmaptofile (Bitmap Bitmap, String _file) throws Ioexcep tion {//_file = <span style= "font-family:arial, Helvetica, Sans-serif;" >getsdpath () + "</span><span style=" font-family:arial, Helvetica, Sans-serif; " >/xx Custom Folders </span><span style= "font-family:arial, Helvetica, Sans-serif;" >/hot.png</span><span style= "font-family:arial, Helvetica, Sans-serif;" > "</span> bufferedoutputstream os = null; try {File File = new file (_file); String _filepath_file.replace (File.separatorchar +//File.getname (), ""); int end = _file.lastindexof (File.separator); String _filepath = _file.substring (0, end); File FilePath = newFile (_filepath); if (!filepath.exists ()) {filepath.mkdirs (); } file.createnewfile (); OS = new Bufferedoutputstream (new FileOutputStream (file)); Bitmap.compress (Bitmap.CompressFormat.PNG, MB, OS); } finally {if (OS! = null) {try {os.close (); } catch (IOException e) {log.e (Tag_error, E.getmessage (), E); } } } }
<pre name= "code" class= "Java" >//read public class Mainact extends Activity {/** Called when the activity is FIR St created. */Private ImageView img; SD Picture Path private String filepath = <span style= "font-family:arial, Helvetica, Sans-serif;" >getsdpath () + "</span><span style=" font-family:arial, Helvetica, Sans-serif; " >/xx Custom Folders </span><span style= "font-family:arial, Helvetica, Sans-serif;" >/hot.png</span><span style= "font-family:arial, Helvetica, Sans-serif;" > </span> @Override public void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.main); img = (ImageView) Findviewbyid (r.id.img); File File = new file (filepath); if (file.exists ()) {Bitmap BM = bitmapfactory.decodefile (filepath); Display a picture in ImageView IMg.setimagebitmap (BM); } }}
/** * Get SDK Path * @return */public static String Getsdpath () { File sddir = null; Boolean sdcardexist = Environment.getexternalstoragestate () . Equals (Android.os.Environment.MEDIA_MOUNTED); Determine if the SD card exists if (sdcardexist) { sddir = environment.getexternalstoragedirectory ();//Get with directory } return sddir.tostring (); }