//拍照
Intent cIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// 指定调用相机拍照后照片的储存路径
cIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
startActivityForResult(cIntent, Constant.PHOTO_REQUEST_TAKEPHOTO);
//裁剪-----------------------------------------------------
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", 2);
intent.putExtra("aspectY", 3);
// outputX,outputY 是剪裁图片的宽高
intent.putExtra("outputX", 100);
intent.putExtra("outputY", 150);
intent.putExtra("return-data", true);
// 添加
intent.putExtra("scale", false);
startActivityForResult(intent, Constant.PHOTO_REQUEST_CUT);
//-------------------------------------------------------------
if (data != null) {
Bundle bundle = data.getExtras();
if (bundle != null) {
Bitmap photo = bundle.getParcelable("data");
}
}
//选图
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 3);
intent.putExtra("aspectY", 2);
intent.putExtra("outputX", 300);
intent.putExtra("outputY", 200);
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, Constant.CHOOSE_SMALL_PICTURE);
//Bitmap转化为Base64
private String encodeToBaseByte(Bitmap bitmap) {
try {
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
byte[] buffer = out.toByteArray();
byte[] encode = Base64.encode(buffer, Base64.DEFAULT);
return new String(encode);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}