如何在 android 中灵活裁剪位图图像?

how to make flexible cropping of bitmap image in android ?

在Android我创建了一个基于相机的应用程序。现在我要自定义我的相机应用程序拍摄的图像。当我裁剪时,它只会裁剪图像的 Top_Left 个角。我必须裁剪图像中的任何地方。引导我。

提前致谢。

我使用了这个代码;

 Display d = getWindowManager().getDefaultDisplay();
        int x = d.getWidth();
        int y = d.getHeight();

        bmp.setDensity(Bitmap.DENSITY_NONE);
        bmp = Bitmap.createBitmap(bmp, 0, 0, x, bmp.getHeight());

        if (imViewAndroid != null){
            imViewAndroid.setImageBitmap(bmp);
        }

对于裁剪,有许多 android 库可用于灵活裁剪图像。我在我的项目中使用了 com.soundcloud.android.crop 库,它运行良好。

步骤:

  1. 从 git 中心下载声音云裁剪工具库。
  2. 将 lib 文件夹粘贴到您的项目中,
  3. 在 setting.gradle 文件中添加您的库 class。
  4. 如果有必要,在项目结构->依赖->库->[声音云的精确扩展]中添加该库
  5. 根据需要在项目中使用声音云裁剪的方法class。
  6. 构建项目。

编码愉快!!