Android剪切图片

项目需求中用到剪切图片功能,在网上打了比较好的解决方案,分享下。

参考:http://www.linuxidc.com/Linux/2012-11/73940.htm

贴出部分代码:

private android.view.View.OnClickListener onClickListener = new android.view.View.OnClickListener() {@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.my_btn_cilp: //剪切大图//(file://)必须要加mImageCaptureUri = Uri.parse("file://"+imageFilePath);//大图使用URLIntent 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", 600);intent.putExtra("outputY", 600);intent.putExtra("scale", true);intent.putExtra("return-data", false);intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());intent.putExtra("noFaceDetection", true); // no face detection//注意Intent.createChooser的使用,选择多个操作应用startActivityForResult(Intent.createChooser(intent, "选择"), CHOOSE_BIG_PICTURE);break;case R.id.my_btn_find://选择图库Intent intentimage = new Intent(Intent.ACTION_PICK, null);intentimage.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,"image/*");startActivityForResult(intentimage, PICK_FROM_FILE);break;case R.id.my_btncilp_thumb: //剪切缩略图//通过intent中设置的type属性来判断具体调用哪个程序的Intent intentThumb = new Intent(Intent.ACTION_GET_CONTENT, null);intentThumb.setType("image/*");intentThumb.putExtra("crop", "true");intentThumb.putExtra("aspectX", 2);intentThumb.putExtra("aspectY", 1);intentThumb.putExtra("outputX", 200);intentThumb.putExtra("outputY", 100);intentThumb.putExtra("scale", true);intentThumb.putExtra("return-data", true);intentThumb.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());intentThumb.putExtra("noFaceDetection", true); // no face detectionstartActivityForResult(intentThumb, CHOOSE_BIG_PICTURE_SAVE);break;default:break;}}};

@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {Toast.makeText(MainActivity.this,"這是拍照所得" + requestCode + "resultCode===" + resultCode+ "RESULT_OK======" + RESULT_OK, Toast.LENGTH_LONG).show();if (resultCode != RESULT_OK) {return;}switch (requestCode) {case PICK_FROM_FILE://缩略图使用bitmapmImageCaptureUri = data.getData();Log.i("cilp", "CHOOSE_BIG_PICTURE: data = " + data);//it seems to be null if(mImageView != null){  Bitmap bitmap = decodeUriAsBitmap(mImageCaptureUri);//decode bitmap  mImageView.setImageBitmap(bitmap); }break;case CHOOSE_BIG_PICTURE:saveBigmap();break;case CHOOSE_BIG_PICTURE_SAVE: if(data != null){ saveCutPic(data); }break;default:break;}}

注:示例工程,给出了剪切大图、缩略图的比较以及Intent.createChooser的使用

另外:补充下设置 RadioButton在文字 的右边 ,使用属性android:drawableRight="@android:drawable/btn_radio"

示例图:
Android剪切图片

更多相关文章

  1. Android中ProgressDialog的简单示例
  2. android从网上加载图片简单示例
  3. android opengl开发示例代码
  4. android中 MediaStore提取缩略图和原始图像
  5. Android 经典示例,初学者的绝好源码资料
  6. Android基础系列-----------Android进程/线程管理应用示例(Androi
  7. android AndroidManifest.xml 权限示例
  8. shape.gradient使用示例
  9. Android ApiDemos示例解析(140):Views->Layouts->Baseline->Nest

随机推荐

  1. Android的Window类
  2. 针对安卓软硬件碎片化,谷歌为何不作为?(转)
  3. 如何选好Android开发书籍和教程[总结]
  4. Android事件分发机制源码分析之View篇
  5. Android多线程之AsycnTask
  6. 模拟器上安装Android(安卓)Market
  7. android 阅读器(寻爱好者共同学习进步)
  8. Qt on Android:怎样适应不同的屏幕尺寸
  9. Android[中级教程]第五章 XML解析之PULL
  10. android 自动开关机