繁体   English   中英

保存在图库中之前如何裁剪图像数据?

[英]How to crop the image data before saving the in gallery?

我正在使用相机API2开发相机应用。 我有相机预览。 如您所见,我可以选择自己感兴趣的领域。 我怎么想只从矩形内的区域拍照。 有谁知道如何实现这一目标? 如果您已阅读过任何教程/示例代码,请发布链接。

我的相机应用程序的屏幕截图

完成捕获图像后,您将获得比较麻烦的图像路径或存储在onActivityResult()中获得的位图以进行捕获。

现在,使用下面的代码执行该图像的裁剪:

public void performCrop(){
    //call the standard crop action intent (the user device may not support it)
Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
    //indicate image type and Uri
cropIntent.setDataAndType(picUri, "image/*");
    //set crop properties
cropIntent.putExtra("crop", "true");
    //indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
    //indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
    //retrieve data on return
cropIntent.putExtra("return-data", true);
    //start the activity - we handle returning in onActivityResult
startActivityForResult(Intent.createChooser(cropIntent,"Cropping"), PIC_CROP);

}

现在,再次在onActivityResult()内部匹配您的PIC_CROP请求代码,并得到如下结果图像:

//get the returned data
Bundle extras = data.getExtras();
//get the cropped bitmap
Bitmap thePic = extras.getParcelable("data");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM