【问题标题】:Cropping image in android without using the crop intent在不使用裁剪意图的情况下在 android 中裁剪图像
【发布时间】:2014-07-25 17:38:11
【问题描述】:

我正在尝试开发一个小型裁剪应用程序。我将在相机窗口上使用覆盖,就像我们通常在条形码扫描仪中使用的那样。但是我想在用户单击图片后裁剪图像的覆盖部分并只存储非覆盖部分。我尝试了原生裁剪功能,但它告诉用户选择裁剪部分。我想直接裁剪照片并将其保存在图库中。我怎样才能做到这一点??

现在我正在使用以下代码进行裁剪......

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);
}

【问题讨论】:

    标签: android crop


    【解决方案1】:

    我假设您有一个带有原始图像的 Bitmap 实例。在这种情况下,只需使用Bitmap.createBitmap() 选择您需要的区域。

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

    【讨论】:

      猜你喜欢
      • 2015-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多