Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中以编程方式裁剪特定大小的图像_Android - Fatal编程技术网

如何在android中以编程方式裁剪特定大小的图像

如何在android中以编程方式裁剪特定大小的图像,android,Android,我正在尝试使用位图创建方法裁剪图像。但我无法从谷歌Pixel mobile获得准确的结果。请帮帮我,我如何做到这一点?为了供您参考,我在下面提到了我的代码 提前谢谢 private void cropCapturedImage(File mFile) { getActivity().runOnUiThread(() -> { Bitmap capturedImagebitmap, rotatedBitmap; capturedImagebitmap

我正在尝试使用位图创建方法裁剪图像。但我无法从谷歌Pixel mobile获得准确的结果。请帮帮我,我如何做到这一点?为了供您参考,我在下面提到了我的代码

提前谢谢

private void cropCapturedImage(File mFile) {
    getActivity().runOnUiThread(() -> {
        Bitmap capturedImagebitmap, rotatedBitmap;
        capturedImagebitmap = BitmapFactory.decodeFile(mFile.getPath());
        final BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
        bitmapOptions.inTargetDensity = 1;
        capturedImagebitmap.setDensity(Bitmap.DENSITY_NONE);

        int height = (int) (capturedImagebitmap.getHeight() * 0.17);
        int y = (int)(capturedImagebitmap.getHeight() * 0.35);
        Log.e("Camera",">>"+height+">>"+y);
        Bitmap resizedBitmap = Bitmap.createBitmap(capturedImagebitmap, 0, y, capturedImagebitmap.getWidth(), height);});
}

我没有旋转图像。现在我已经旋转了图像,图像裁剪效果很好。下面我提到了工作代码

try {
ei = new ExifInterface(mFile.getAbsolutePath());

int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_UNDEFINED);


switch (orientation) {

case ExifInterface.ORIENTATION_ROTATE_90:
rotatedBitmap = rotateImage(capturedImagebitmap, 90);
break;

case ExifInterface.ORIENTATION_ROTATE_180:
rotatedBitmap = rotateImage(capturedImagebitmap, 180);
break;

case ExifInterface.ORIENTATION_ROTATE_270:
rotatedBitmap = rotateImage(capturedImagebitmap, 270);
break;

case ExifInterface.ORIENTATION_NORMAL:
rotatedBitmap = capturedImagebitmap;
break;

default:
rotatedBitmap = capturedImagebitmap;

}
// cropping image
int height = (int) (rotatedBitmap.getHeight() * 0.2);
int y = (int) (rotatedBitmap.getHeight() * 0.4);

Bitmap resizedBitmap = Bitmap.createBitmap(rotatedBitmap, 0, y, rotatedBitmap.getWidth(), height);

savebitmap(resizedBitmap);

showPreviewImage();

} catch (IOException e) {
e.printStackTrace();
}
public static Bitmap rotateImage(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(),
matrix, true);
}

您试图将图像调整为什么尺寸?