从形象定位 [英] Image Orientation from

查看:164
本文介绍了从形象定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法得到一个图片,你拿着相机的方位?

我使用下面的方法来恢复在我的画廊图像的方向,但如果我拍照与摄像头就不能正常工作。

 公共静态INT getImageOrientation(上下文的背景下,乌里photoUri){
    INT方向= -1;
    光标光标= context.getContentResolver()查询(photoUri,
            新的String [] {} MediaStore.Images.ImageColumns.ORIENTATION,NULL,NULL,NULL);    如果(光标=空&放大器;!&放大器; cursor.getCount()== 1){
        cursor.moveToFirst();
        取向= cursor.getInt(0);
    }    返回的方向;
}


解决方案

您可以从下面code获取图像的方向:

  {尝试
    context.getContentResolver()有NotifyChange(imageUri,NULL);
    文件镜像文件=新的文件(的ImagePath);    ExifInterface EXIF​​ =新ExifInterface(imageFile.getAbsolutePath());
    INT方向= exif.getAttributeInt(ExifInterface.TAG_ORIENTATION,ExifInterface.ORIENTATION_NORMAL);    开关(方向){
    案例ExifInterface.ORIENTATION_ROTATE_270:
        旋转= 270;
        打破;
    案例ExifInterface.ORIENTATION_ROTATE_180:
        旋转= 180;
        打破;
    案例ExifInterface.ORIENTATION_ROTATE_90:
        旋转= 90;
        打破;
    }    Log.i(RotateImage,方向的Exif:+方向);
    Log.i(RotateImage,旋转值:+旋转);
}赶上(例外五){
    e.printStackTrace();
}

下面首先你要保存在SD卡上拍摄的图像,然后从该图像的保存路径获取图像的URI。然后传递URI作为imageUri在发布code。

Is there a way to get the orientation of a picture that you took with the camera?

I am using the method below to recover orientations of images that are in my gallery, but if I take pictures with the camera it does not work.

   public static int getImageOrientation(Context context, Uri photoUri) {
    int orientation = -1;
    Cursor cursor = context.getContentResolver().query(photoUri,
            new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null);

    if (cursor != null && cursor.getCount() == 1) {
        cursor.moveToFirst();
        orientation = cursor.getInt(0);
    }

    return orientation;
}

解决方案

You can get the orientation of image from below code:

try {
    context.getContentResolver().notifyChange(imageUri, null);
    File imageFile = new File(imagePath);

    ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
    int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);

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

    Log.i("RotateImage", "Exif orientation: " + orientation);
    Log.i("RotateImage", "Rotate value: " + rotate);
} catch (Exception e) {
    e.printStackTrace();
}

Here first you have to save the captured image on sd card and then fetch the image Uri from the path where the image is saved. Then pass that Uri as imageUri in the posted code.

这篇关于从形象定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆