String path = Environment.getExternalStorageDirectory().getAbsoluteFile() + "/ss.png";
File f = new File(path);
if (!f.exists()) {
try {
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
Uri img = Uri.fromFile(f);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
intent.setType("image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);// 裁剪框比例
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 80);// 输出图片大小
intent.putExtra("outputY", 80);
intent.putExtra("scale", true);// 如果选择的图小于裁剪大小则进行放大
intent.putExtra("scaleUpIfNeeded", true);// 如果选择的图小于裁剪大小则进行放大
intent.putExtra("return-data", true);// 是否输出bitmap
intent.putExtra(MediaStore.EXTRA_OUTPUT, img);// 需要直接输出到文件的URI
intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());// 输出格式
startActivityForResult(intent, 1);
// 大图可以考虑直接写入文件而不返回bitmap
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap bmp = data.getParcelableExtra("data");
iv.setImageBitmap(bmp);
}