相关疑难解决方法(0)

为什么在Android上的某些设备上使用相机意图捕获的图像会被旋转?

我正在捕捉图像并将其设置为图像视图.

public void captureImage() {

    Intent intentCamera = new Intent("android.media.action.IMAGE_CAPTURE");
    File filePhoto = new File(Environment.getExternalStorageDirectory(), "Pic.jpg");
    imageUri = Uri.fromFile(filePhoto);
    MyApplicationGlobal.imageUri = imageUri.getPath();
    intentCamera.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
    startActivityForResult(intentCamera, TAKE_PICTURE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intentFromCamera) {
    super.onActivityResult(requestCode, resultCode, intentFromCamera);

    if (resultCode == RESULT_OK && requestCode == TAKE_PICTURE) {

        if (intentFromCamera != null) {
            Bundle extras = intentFromCamera.getExtras();
            if (extras.containsKey("data")) {
                bitmap = (Bitmap) extras.get("data");
            }
            else {
                bitmap = getBitmapFromUri();
            }
        }
        else {
            bitmap = getBitmapFromUri();
        }
        // …
Run Code Online (Sandbox Code Playgroud)

camera android image rotation android-camera-intent

344
推荐指数
11
解决办法
19万
查看次数

某些设备(不是EXIF)捕获Android相机无法解释的旋转

我正在做的事情似乎应该很简单,但在我阅读了每一个可能的Stackoverflow答案之后我仍然迷失了,我可以找到并搜索我能找到的每篇文章.

我正在使用预览SurfaceView并从我在AndroidManifest.xml中为screenOrientation ="landscape"设置的活动中捕获图像.

我按照示例相机应用程序代码进行操作,直到我在运行1.5的一些摩托罗拉设备上尝试我的应用程序之前一直工作.

我让OrientationEventListener运行正常,我使用反射来查看是否设置旋转:

final int latchedOrientation = roundOrientation(mLastOrientation + 90);

Parameters parameters = preview.camera.getParameters();

JPLog.d("Setting camera rotation = %d", latchedOrientation);
try {
    // if >= 2.0
    Method method = Camera.Parameters.class.getMethod("setRotation",
        int.class);

    if(method != null) {
        method.invoke(parameters, latchedOrientation);
    }

} catch(Throwable t) {
    // if < 2.0
    parameters.set("rotation", latchedOrientation);
}

preview.camera.setParameters(parameters);
Run Code Online (Sandbox Code Playgroud)

NexusOne(OS 2.2) - 效果很好.latchedOrientation = 0,图片OK在EXIF标题中没有任何旋转.

T-Mobile G1(OS 1.6) - 也很棒.latchedOrientation = 0,图片确定.

摩托罗拉Backflip(OS 1.5) - 图像旋转.latchedOrientation = 0,图片中没有EXIF旋转.

Motorola CLIQ(OS 1.5) - 图像旋转.latchedOrientation = 0,图片中没有EXIF旋转.

这些摩托罗拉设备发生了什么变化?我认为我的问题是摩托罗拉相机驱动程序没有旋转图像,所以找到了Android的Sanselan EXIF阅读课,并准备自己旋转它们.有趣的是,有EXIF标题但没有旋转元素. …

camera android rotation capture orientation

29
推荐指数
2
解决办法
3万
查看次数