Save image of Android board

Source: Internet
Author: User

(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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.