选择图片并裁剪

来源:互联网 发布:知党史感党恩跟党走 编辑:程序博客网 时间:2024/04/28 11:45
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);// 是否输出bitmapintent.putExtra(MediaStore.EXTRA_OUTPUT, img);// 需要直接输出到文件的URIintent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());// 输出格式startActivityForResult(intent, 1);// 大图可以考虑直接写入文件而不返回bitmap
@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);Bitmap bmp = data.getParcelableExtra("data");iv.setImageBitmap(bmp);}


0 0
原创粉丝点击