码迷,mamicode.com
首页 > 其他好文 > 详细

使用系统默认接口来剪切图片

时间:2014-10-20 11:53:04      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:剪切图片

如果调用系统的图片接口:

      Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
//		intent.addCategory(Intent.CATEGORY_OPENABLE);
//		intent.setType("image/*");
            startActivityForResult(intent, REQUEST_CODE_SELECT_PHOTO);

  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
 if (requestCode == REQUEST_CODE_SELECT_PHOTO) {
            try {
                //onPhotoSelected(data);
                final Uri originalUri = data.getData();
                if (originalUri == null) {
                    return;
                }
                startPhotoZoom(originalUri);
            } catch (Exception e) {
                if (LogSettings.MARKET) {
                    MktLog.e(TAG, "onPhotoSelected() : " + e.getMessage());
                }
            }
            return;
        }
}

public void startPhotoZoom(Uri uri) {              //这个是调用裁剪图片的接口
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("outputX", 150);
        intent.putExtra("outputY", 150);
        intent.putExtra("return-data", true);
        startActivityForResult(intent, REQUEST_CODE_SELECT_CUT_PHOTO);
    }

裁剪完在onActivityResult中可以用:

if(requestCode == REQUEST_CODE_SELECT_CUT_PHOTO) {
            try {
                Bitmap bm = data.getParcelableExtra("data");

            } catch (Exception e) {
                if (LogSettings.MARKET) {
                    MktLog.e(TAG, "onPhotoSelected() : " + e.getMessage());
                }
            }

裁剪图片的接口:

bubuko.com,布布扣


使用系统默认接口来剪切图片

标签:剪切图片

原文地址:http://blog.csdn.net/baidu_nod/article/details/40296547

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!