Android中的相机定向问题 [英] Camera orientation issue in Android

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

问题描述

我正在建立一个使用相机拍照的应用程序。这是我的源代码来执行此操作:

I am building an application that uses camera to take pictures. Here is my source code to do this:

        File file = new File(Environment.getExternalStorageDirectory(),
            imageFileName);
    imageFilePath = file.getPath();
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    startActivityForResult(intent, ACTIVITY_NATIVE_CAMERA_AQUIRE);

onActivityResult() BitmapFactory.decodeStream()来接收图片。

当我在Nexus上运行我的应用程序时, 。但是当我运行在Samsung Galaxy S或HTC Inspire 4G上时,图片的方向不正确。

When I run my application on Nexus one, it runs well. But when I run on Samsung Galaxy S or HTC Inspire 4G, the image's direction is not correct.


  • 真实的图像(保存在SD卡上)总是旋转90度。
    (拍摄后的图像预览)(SD卡上的真实图片)

  • Capture with portrait mode, the real image (save on SD card) always rotates 90 degree. (image preview after shot) (real image on SD card)

,一切都很好。

(拍摄后的图像预览) (SD卡上的实际图片)

(image preview after shot) (real image on SD card)

请帮我解决这个问题。


推荐答案

这里有很多类似的主题和问题。由于您不是在编写自己的相机,我认为这可以归结为:

There are quite a few similar topics and issues around here. Since you're not writing your own camera, I think it boils down to this:

一些设备在保存图像之前旋转图像,而其他设备只是简单地添加方向标记照片的exif数据。

some devices rotate the image before saving it, while others simply add the orientation tag in the photo's exif data.

我建议您检查照片的exif数据,并特别查找

I'd recommend checking the photo's exif data and looking particularly for

ExifInterface exif = new ExifInterface(SourceFileName);     //Since API Level 5
String exifOrientation = exif.getAttribute(ExifInterface.TAG_ORIENTATION);

由于照片在您的应用中正确显示,我不知道问题出在哪里,这肯定会使你在正确的道路上!

Since the photo is displaying correctly in your app, i'm not sure where the problem is, but this should definitely set you on the right path!

这篇关于Android中的相机定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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