Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.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
Java 将图像旋转到手机';使用相机拍摄时的方向:Android_Java_Android_Android Camera_Image Rotation - Fatal编程技术网

Java 将图像旋转到手机';使用相机拍摄时的方向:Android

Java 将图像旋转到手机';使用相机拍摄时的方向:Android,java,android,android-camera,image-rotation,Java,Android,Android Camera,Image Rotation,我正在构建一个Android应用程序,我从手机的摄像头中点击一张照片,并将其显示在ImageView中,它会自动逆时针旋转90度。我希望以手机点击的方向显示它,而不是让它旋转 有人能提供相关的代码片段或指向相关文档的指针吗?检查 用这种方法它会帮助你的 /* * 1 = Horizontal (normal) * 2 = Mirror horizontal * 3 = Rotate 180 * 4 = Mirror vertical * 5 = Mirror horizo

我正在构建一个Android应用程序,我从手机的摄像头中点击一张照片,并将其显示在ImageView中,它会自动逆时针旋转90度。我希望以手机点击的方向显示它,而不是让它旋转

有人能提供相关的代码片段或指向相关文档的指针吗?

检查


用这种方法它会帮助你的

/*   
 * 1 = Horizontal (normal) 
 * 2 = Mirror horizontal 
 * 3 = Rotate 180 
 * 4 = Mirror vertical 
 * 5 = Mirror horizontal and rotate 270 CW 
 * 6 = Rotate 90 CW 
 * 7 = Mirror horizontal and rotate 90 CW 
 * 8 = Rotate 270 CW
 */
public static Bitmap getRotateBitmapImage(Bitmap bm, int newHeight,int newWidth, int exifOrientation) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    switch (exifOrientation) {
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotate = 270;
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotate = 180;
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotate = 90;
        break;
    case ExifInterface.ORIENTATION_TRANSPOSE:
        rotate = 45;
        break;
    case 0:
        rotate = 360;
        break;
    default:
        break;
    }
    matrix.postRotate(rotate);
    // resizedBitmap = Bitmap.createScaledBitmap(bm, 65, 65, true);
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}

我正在使用Intenet xyz=newintent(Mediastore.ACTION\u IMAGE\u CAPTURE)来捕获图像。此存储的格式是什么?如何将此处捕获的图像对象传递给此处描述的函数?新高度、新宽度如何?如果不缩放位图,可以忽略新高度和新宽度部分。只需使用bitmap.getWidth()和bitmap.getHeight()。您可以在使用bitmap.createBitmap时删除新的高度/宽度
/*   
 * 1 = Horizontal (normal) 
 * 2 = Mirror horizontal 
 * 3 = Rotate 180 
 * 4 = Mirror vertical 
 * 5 = Mirror horizontal and rotate 270 CW 
 * 6 = Rotate 90 CW 
 * 7 = Mirror horizontal and rotate 90 CW 
 * 8 = Rotate 270 CW
 */
public static Bitmap getRotateBitmapImage(Bitmap bm, int newHeight,int newWidth, int exifOrientation) {
    int width = bm.getWidth();
    int height = bm.getHeight();
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    Matrix matrix = new Matrix();
    matrix.postScale(scaleWidth, scaleHeight);
    switch (exifOrientation) {
    case ExifInterface.ORIENTATION_ROTATE_270:
        rotate = 270;
        break;
    case ExifInterface.ORIENTATION_ROTATE_180:
        rotate = 180;
        break;
    case ExifInterface.ORIENTATION_ROTATE_90:
        rotate = 90;
        break;
    case ExifInterface.ORIENTATION_TRANSPOSE:
        rotate = 45;
        break;
    case 0:
        rotate = 360;
        break;
    default:
        break;
    }
    matrix.postRotate(rotate);
    // resizedBitmap = Bitmap.createScaledBitmap(bm, 65, 65, true);
    Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
    return resizedBitmap;
}