读书人

Android 代码片断-从相册或相机获取图

发布时间: 2013-10-22 16:17:03 作者: rapoo

Android 代码片段---从相册或相机获取图片保存并处理

@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {// TODO Auto-generated method stubswitch (resultCode) {case RESULT_OK:if (requestCode == UConstants.CAPUTRE){// Load up the image's dimensions not the image itselftry {BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();bmpFactoryOptions.inJustDecodeBounds = true;Bitmap bmp = BitmapFactory.decodeFile(urlTempPic,bmpFactoryOptions);int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth / (float) 1080);if (widthRatio > 1){bmpFactoryOptions.inSampleSize = widthRatio;}bmpFactoryOptions.inJustDecodeBounds = false;bmp = BitmapFactory.decodeFile(urlTempPic, bmpFactoryOptions);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}else if (requestCode == UConstants.GETIMAGE){Uri imageFileUri = data.getData();try {BitmapFactory.Options bmpFactoryOptions = new BitmapFactory.Options();bmpFactoryOptions.inJustDecodeBounds = true;Bitmap bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri), null, bmpFactoryOptions);int widthRatio = (int) Math.ceil(bmpFactoryOptions.outWidth/ (float) 1080);if (widthRatio > 1) {bmpFactoryOptions.inSampleSize = widthRatio;}bmpFactoryOptions.inJustDecodeBounds = false;bmp = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageFileUri),null, bmpFactoryOptions);} catch (Exception e) {// TODO: handle exception}}break;default:break;}}



1楼u011960402昨天 21:10
加点注释会比较好

读书人网 >Android

热点推荐