Private ImageView iv_user_photo; private String fileName = ""; private File tempFile; private int crop = 300; // crop the private static final int OPEN_CAMERA_CODE = 10; private static final int OPEN_GALLERY_CODE = 11; private static final int CROP_PHOTO_CODE = 12; private OnClickListener popupener witemonclick = new OnClickListener () {@ Override public void onClick (View v) {menuWindow. dismiss (); switc H (v. getId () {// photograph case R. id. btn_camera: initFile (); openCamera (); break; // album case R. id. btn_gallery: initFile (); openGallery (); break; default: break ;}}; public void initFile () {if (fileName. equals ("") {if (FileUtil. existSDCard () {String path = Environment. getExternalStorageDirectory () + File. separator + "JanuBookingOnline" + File. separator; FileUtil. mkdir (path); Logger. I ("path:" + pat H); fileName = path + "user_head_photo.jpg"; tempFile = new File (fileName);} else {CommonUitl. toast (context, "Please insert SD card") ;}}/ *** call camera */public void openCamera () {Intent intent = new Intent (MediaStore. ACTION_IMAGE_CAPTURE); // enable the camera intent. putExtra ("output", Uri. fromFile (tempFile); startActivityForResult (intent, OPEN_CAMERA_CODE);}/*** open album */public void openGallery () {Intent intent = ne W Intent (Intent. ACTION_PICK); // open the album intent. setDataAndType (MediaStore. images. media. INTERNAL_CONTENT_URI, "image/*"); intent. putExtra ("output", Uri. fromFile (tempFile); startActivityForResult (intent, OPEN_GALLERY_CODE);}/*** crop image ** @ param uri */public void cropPhoto (Uri uri) {Intent intent = new Intent ("com. android. camera. action. CROP "); intent. setDataAndType (uri, "image/*"); intent. putExtra ("o Utput ", Uri. fromFile (tempFile); intent. putExtra ("crop", true); intent. putExtra ("aspectX", 1); intent. putExtra ("aspectY", 1); intent. putExtra ("outputX", crop); intent. putExtra ("outputY", crop); startActivityForResult (intent, CROP_PHOTO_CODE) ;}@ Override protected void onActivityResult (int requestCode, int resultCode, Intent data) {if (resultCode = 1) return; switch (requestCode) {case OPEN_CAM ERA_CODE: cropPhoto (Uri. fromFile (tempFile); break; case OPEN_GALLERY_CODE: cropPhoto (data. getData (); break; case CROP_PHOTO_CODE: try {BitmapFactory. options options = new BitmapFactory. options (); options. inSampleSize = 2; Bitmap bitmap = BitmapFactory. decodeFile (fileName, options); if (bitmap! = Null) {iv_user_photo.setImageBitmap (bitmap); CommonUitl. sharedPreferences (context, AppConstants. USER_PHOTO, fileName) ;}} catch (Exception e) {e. printStackTrace ();} break; default: break;} super. onActivityResult (requestCode, resultCode, data );}
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/10025B047-0.png "/>
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/10025A919-1.png "/>
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1002563O6-2.png "/>
This article is from the "wintitle" blog. For more information, contact the author!