Android photos and albums pick pictures

Source: Internet
Author: User

Have done a few photos, album selection of pictures, but can not remember, this time to publish a simple save under

Private Static Final int Photo_graph = 1; // Take pictures    Private Static Final int // album capture    Private Static Final String Image_type = "image/*";
1  Public voidTakephoto () {2     3String sdstate =environment.getexternalstoragestate (); 4   if(Sdstate.equals (environment.media_mounted))5             {  6Imgfilename = System.currenttimemillis () + ". jpg";7Intent Intent =NewIntent ("Android.media.action.IMAGE_CAPTURE");8Intent.putextra (Mediastore.extra_output, Uri.fromfile (NewFile (9 environment.getexternalstoragedirectory (), Imgfilename ));TenIntent.putextra (mediastore.extra_video_quality, 0); One Startactivityforresult (Intent, photo_graph); A Dialog.dismiss (); -}Else{   -Toast.maketext (Getthis (), "Memory card not Present", Toast.length_short). Show ();  the             }            -}
Take Pictures
//callback functionprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {        Super. Onactivityresult (Requestcode, ResultCode, data);if(ResultCode = =RESULT_OK) {            Switch(requestcode) { CaseNONE: Break;  CasePhoto_graph://Take PicturesString Myjpgpath = environment.getexternalstoragedirectory () + "/" +Imgfilename; if(Imagethumbnail.isfileexit (myjpgpath) = =true){Img_sfz.setimagebitmap (Imagethumbnail.getimagethumbnail (Myjpgpath, Img_sfz.getwidth (), Img_SFZ.get Height ()));                }                 Break;  CasePhoto_album://album capture//the original resource address of the photoUri Originaluri =Data.getdata (); Try {                    //get the path to the picture:String[] proj ={MediaStore.Images.Media.DATA}; Cursor= Managedquery (Originaluri, Proj,NULL,NULL,NULL); //as I understand it, this is the index value of the image that the user chooses.                    intColumn_index =Cursor.getcolumnindexorthrow (MediaStore.Images.Media.DATA);                    Cursor.movetofirst (); //finally get the picture path according to the index valueString Imgpath =cursor.getstring (Column_index); if(Imagethumbnail.isfileexit (imgpath) = =true) {Img_sfz.setimagebitmap (Imagethumbnail.getimagethumbnail (Imgpath, Img_sfz.getwidth (), IMG_SFZ.G Etheight ()));                    }                } Catch(Exception e) {//Todo:handle Exception                }                                 Break; default:                 Break; }        }
/*** Image compression Display *@paramImagePath *@paramWidth *@paramHeight *@return     */     Public StaticBitmap Getimagethumbnail (String ImagePath,intwidth,intheight) {Bitmap Bitmap=NULL; Bitmapfactory.options Options=Newbitmapfactory.options (); Options.injustdecodebounds=true; //get the width and height of this picture, note that the bitmap here is nullBitmap =bitmapfactory.decodefile (ImagePath, Options); Options.injustdecodebounds=false;//set to False//Calculating the zoom ratio        inth =Options.outheight; intW =Options.outwidth; intBewidth = w/width; intBeheight = h/height; intbe = 1; if(Bewidth <beheight) { be=Bewidth; } Else{ be=Beheight; }        if(Be <= 0) { be= 1; } options.insamplesize=Be ; //re-read the picture, read the scaled bitmap, and note this time to set the Options.injustdecodebounds to FalseBitmap =bitmapfactory.decodefile (ImagePath, Options); //use Thumbnailutils to create thumbnails, where you want to specify which bitmap object to scaleBitmap =thumbnailutils.extractthumbnail (bitmap, width, height, thumbnailutils.options_recycle_input); returnbitmap; }
image Compression Display

Android photos and albums pick pictures

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.