二、从相册截小图
Intent
intent = new
Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("crop",
"true");
intent.putExtra("aspectX",
2);
intent.putExtra("aspectY",
1);
intent.putExtra("outputX",
200);
intent.putExtra("outputY",
100);
intent.putExtra("scale",
true);
intent.putExtra("return-data",
true);
intent.putExtra("outputFormat",
Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection",
true);
//
no face detection
startActivityForResult(intent,
CHOOSE_SMALL_PICTURE);
三、对应的onActivityResult可以这样处理返回的数据
switch
(requestCode) {
case
CHOOSE_BIG_PICTURE:
Log.d(TAG,
"CHOOSE_BIG_PICTURE:
data = "
+ data);//it
seems to be null
if(imageUri
!= null){
Bitmap
bitmap = decodeUriAsBitmap(imageUri);//decode
bitmap
imageView.setImageBitmap(bitmap);
}
break;
case
CHOOSE_SMALL_PICTURE:
if(data
!= null){
Bitmap
bitmap = data.getParcelableExtra("data");
imageView.setImageBitmap(bitmap);
}else{
Log.e(TAG,
"CHOOSE_SMALL_PICTURE:
data = "
+ data);
}
break;
default:
break;
}
private
Bitmap decodeUriAsBitmap(Uri uri){
Bitmap
bitmap = null;
try
{
bitmap
= BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));
}
catch
(FileNotFoundException e) {
e.printStackTrace();
return
null;
}
return
bitmap;
}
以上就是Android实现拍照截图功能的方法,希望对大家的学习有所帮助。
注:相关教程知识阅读请移步到Android开发频道。










