简体   繁体   English

在不使用裁剪意图的情况下在android中裁剪图像

[英]Cropping image in android without using the crop intent

I am trying to develop a small cropping application. 我正在尝试开发一个小的裁剪应用程序。 I will be using a overlay on the camera window like we normally have in bar code scanners. 我将像通常在条形码扫描仪中那样在相机窗口上使用覆盖层。 But I want to crop the overlay part of the image after user clicks a pic and just store the non-overlay part. 但是我想在用户单击图片后裁剪图像的重叠部分,然后只存储非重叠部分。 I tried the native cropping functionality but it tells the user to select the cropping part. 我尝试了本机裁剪功能,但它告诉用户选择裁剪部分。 I want to directly crop the photo and save it in the gallery. 我想直接裁剪照片并将其保存在图库中。 How can I achieve this?? 我该如何实现?

Now I am using the following code for cropping.... 现在,我正在使用以下代码进行裁剪...。

private void performCrop() {
        // TODO Auto-generated method stub
        //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(cropIntent,AppUtils.PIC_CROP);
}

I assume you have a Bitmap instance with the original image. 我假设您有一个具有原始图像的Bitmap实例。 In that case, just use Bitmap.createBitmap() to select the area you need. 在这种情况下,只需使用Bitmap.createBitmap()选择所需的区域。

Bitmap cropped = Bitmap.createBitmap(bitmap, left, top, width, height);

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

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