简体   繁体   English

自拍的Android Native Camera App Orientation问题

[英]Android Native Camera App Orientation Issue for selfie taken

Followed Android documentation to write code for launching native camera via intent: 遵循Android文档编写用于通过意图启动本机摄像头的代码:
http://developer.android.com/training/camera/photobasics.html http://developer.android.com/training/camera/photobasics.html

Problem : I am using Andorid Native Camera App for taking pictures from my app and launching via intent as mentioned in above link (MediaStore.ACTION_IMAGE_CAPTURE) and camera is launched successfully. 问题 :我正在使用Andorid Native Camera App从我的应用程序中拍照并通过上述链接(MediaStore.ACTION_IMAGE_CAPTURE)中所述的意图启动,并且相机已成功启动。 When I click camera button of Native app to take pictures, image preview is mirrored while taking selfie (left image appears right) which selfie user would hate as image preview is not what he clicked. 当我单击“本机”应用程序的“相机”按钮拍摄照片时,在拍摄自拍照时镜像预览被镜像(左图出现在右边),这是自拍照用户讨厌的自拍照用户,因为图像预览不是他单击的。
Second - once image is clicked, it shows image preview and waits for user input for acceptance or rejection of picture. 其次-单击图像后,它将显示图像预览并等待用户输入以接受或拒绝图片。
Once image is accepted, OnStartActivityResult (as mentioned in above link) function receives the call and saves image to gallery. 接受图像后,OnStartActivityResult(如上面的链接所述)函数将接收该调用并将图像保存到图库。 Strange thing here is that: Image gets inverted by 180 degree and then saved which is very weird behaviour. 奇怪的是:图像反转了180度然后保存,这是非常奇怪的行为。
Finally, two problems here: Image Preview Mirroing issue before user approves and while saving image invert issue (180 degree reverse). 最后,这里有两个问题: 图像预览在用户批准之前出现Mirroing问题,而在保存图像反转问题时(反向180度)。

Device: Samsung A6 Edge 设备:三星A6 Edge
Android: 5.1 的Android: 5.1
Camera In Manifest File: Android.hardware.camera2 as Camera is deprecated Please advise how can i fix above two issues. 清单文件中的Camera Android.hardware.camera2,因为不推荐使用Camera,请告知我如何解决以上两个问题。

Also- I have another doubt : Shall i use android native camera app or write the code using Camera Framework and launch custom camera? 另外- 我还有一个疑问 :我应该使用android native camera应用程序还是使用Camera Framework编写代码并启动自定义相机? My requirement just to click pictures and show preview and save it with correct orientation. 我只需要单击图片并显示预览并以正确的方向保存它。 After searching a lot, I am doubtful - Can native camera app fix these issues? 经过大量搜索后,我很怀疑-本机相机应用程序可以解决这些问题吗? but your expert advise can help on this. 但是您的专家建议可以提供帮助。

Any quick support and guidance on this is highly appreciated. 非常感谢您对此的任何快速支持和指导。 Thanks in advance ! 提前致谢 ! Here is the code: 这是代码:

public void triggerCamera() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File imagePath = AppPhotoHelper.getOutputMediaFile();

    // Continue only if the File was successfully created
    if (imagePath != null) {
        takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                Uri.fromFile(imagePath));
        takePictureIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        this.setImagePath(imagePath);
        this.startActivityForResult(takePictureIntent, CAMERA_PIC_REQUEST);
    }
}

onActivityResult function: onActivityResult函数:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_PIC_REQUEST) {
        if (resultCode == RESULT_OK ) {
           //AppPhotoHelper is my class to show image in gallery
            AppPhotoHelper.displayInGallery(this.getImagePath(), this);
            //Image captured and stored in gallery ... camera invoked for next shot after doing some business processing
            this.triggerCamera();
        }
        else if (resultCode == RESULT_CANCELED) {
            return;
        }
        else {
            return;
        }
    }

}

As mentioned in my post , the native camera app differs from device to device. 如我的帖子所述 ,本机相机应用程序因设备而异。 Did you try your code with another device or emulator? 您是否在其他设备或仿真器上尝试过代码? I published a library on github that solves many issues, including the image orientation across a wide variety of devices. 在github上发布了一个库,解决了许多问题,包括跨多种设备的图像方向。 Feel free to check it out, run the sample code on your device and check if it works properly for your use case. 随时检查它,在设备上运行示例代码,并检查它是否适合您的用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM