RT
1、直接压缩处理显示到ImageView
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE) {
if (resultCode != RESULT_OK) {
return;
}
if (file != null && file.exists()) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
photo = BitmapFactory.decodeFile(file.getPath(), options);
photo_image.setBackgroundDrawable(new BitmapDrawable(photo));
pictureDir = file.getPath();
} else {
Toast.makeText(this, R.string.photo_file_isnull,
Toast.LENGTH_LONG).show();
}
}
}
2、先截图处理再显示到ImageView
<span style="white-space:pre"> </span>@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
Log.i("LPY_DEBUG","拍照后的图片路径为 "+photoFile);
// if(photoFile != null && )
if (photoFile != null && photoFile.exists() && photoFile.length() > 0) {
startPhotoZoom(Uri.fromFile(photoFile));
}
}
if (requestCode == 3) {
if (data != null) {
Bundle bundle = data.getExtras();
if (bundle != null) {
// 裁剪后的图片
bitmap = bundle.getParcelable("data");
if (<span style="font-family: 'Microsoft YaHei';">bitmap</span>!= null) {
Log.i("LPY_DEBUG","进入获取data数据的判断");
iv_userphoto.setImageBitmap(bitmap);
photoFile = new File(Constans.PHOTO_DIR, System.currentTimeMillis() + ".jpg"); // 将图片转换成文件
ImageUtil.saveBitmapToJepgFile(bitmap, photoFile);
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
private void startPhotoZoom(Uri uri) {
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
// crop为true是设置在开启的intent中设置显示的view可以剪裁
intent.putExtra("crop", "true");//发送裁剪信号
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 300);//X方向上的比例
intent.putExtra("aspectY", 190);//Y方向上的比例
// outputX,outputY 是剪裁图片的宽高
intent.putExtra("outputX", 300);//裁剪区的宽
intent.putExtra("outputY", 190);//裁剪区的高
intent.putExtra("return-data", true);//是否返回数据
intent.putExtra("noFaceDetection", true);//关闭人脸检测
intent.putExtra("scale",true);//是否保留比例
startActivityForResult(intent, 3);
}