Android摄像头定位问题摄像头、问题、Android

由网友(孤我)分享简介:在垂直格式拍摄的照片都保存在横向格式,反之亦然。我使用Android摄像头使用此意图pictures taken in vertical format are saved in landscape format and vice-versa. I am using Android camera by using th...

在垂直格式拍摄的照片都保存在横向格式,反之亦然。我使用Android摄像头使用此意图

pictures taken in vertical format are saved in landscape format and vice-versa. I am using Android camera by using this intent

Intent captureImage = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
captureImage.putExtra(MediaStore.EXTRA_OUTPUT, imageFileUri);               
startActivityForResult(captureImage, CAMERA_PIC_REQUEST);

onActivityResult()我只是保存图像的URL到我的数据库,并在列表视图显示它。 但orientatiuon变化。同样会发生,如果我选择的画廊图像,并保存它。

onActivityResult() I am just saving image URL to my database and displaying it in a listview. but there orientatiuon changes. The same will happen if I choose image from gallery and save it.

我想在照片已被采取的方向。我不想去改变它。是任何人有这样的solutin。

I want the orientation in which photo has been taken. I dont want to change it. Is anybody have a solutin on this.

推荐答案

有些设备不旋转图像它被采取之后,但只写它的方位信息为Exif数据中。因此,使用拍摄的照片之前,您应该调用类似的方法:

Some devices doesn't rotate image after it was taken but just write its orientation information into Exif data. So before using taken photo you should call method like :

private int resolveBitmapOrientation(File bitmapFile) throws IOException {
        ExifInterface exif = null;
        exif = new ExifInterface(bitmapFile.getAbsolutePath());

        return exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
    }

要检查它的方向。然后应用:

to check its orientation. Then apply:

private Bitmap applyOrientation(Bitmap bitmap, int orientation) {
        int rotate = 0;
        switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotate = 270;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotate = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotate = 90;
                break;
            default:
                return bitmap;
        }

        int w = bitmap.getWidth();
        int h = bitmap.getHeight();
        Matrix mtx = new Matrix();
        mtx.postRotate(rotate);
        return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
    }

和使用这个新的位图在你的列表视图。或者,它甚至更好调用这个方法您的照片拍摄刚结束,并与新的旋转一周覆盖它。

and use this new bitmap in your listview. Or it's even better to call this methods just after your photo was taken and override it with new rotated one.

阅读全文

相关推荐

最新文章