阅读更多

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"

示例图:

 

  • AndroidCilpImageRefresh.rar (1.2 MB)
  • 下载次数: 0
  • 大小: 8.4 KB
  • 查看图片附件

更多相关文章

  1. 使用多状态按钮ToggleButton
  2. Android(安卓)中的Theme和Style使用
  3. Java代码设置Android全屏
  4. android studio 使用cmake支持C++出现无法sync cmake error的问
  5. Android(安卓)Gallery的使用
  6. 使用Android(安卓)Studio创建Android(安卓)Wear项目
  7. Android中JNI的使用方法
  8. Android游戏引擎《Rokon》
  9. Android系列之Android(安卓)命令行手动编译打包详解

随机推荐

  1. (lintcode)第6题 合并排序数组
  2. (lintcode)第1题 A+B问题
  3. (lintcode)第16题 带重复元素的排列
  4. (lintcode)第452题删除链表中的元素
  5. (lintcode)第3题统计数字
  6. (lintcode)第14题二分查找
  7. (lintcode)第4题 丑数II
  8. (lintcode)第454题 矩阵面积
  9. (lintcode)第5题第k大元素
  10. (lintcode)第18题 带重复元素的子集