【发布时间】:2016-08-04 11:26:10
【问题描述】:
按照 Android 文档编写通过 Intent 启动本机摄像头的代码:
http://developer.android.com/training/camera/photobasics.html
问题:我正在使用 Andorid Native Camera App 从 我的应用程序 拍照并通过上述链接 (MediaStore.ACTION_IMAGE_CAPTURE) 中提到的意图启动并启动相机成功地。当我单击 Native 应用程序的相机按钮拍照时,图像预览在 自拍时被镜像(左图出现在右图),自拍用户会讨厌,因为图像预览不是他点击的。
第二 - 单击图像后,它会显示图像预览并等待用户输入接受或拒绝图片。
一旦图像被接受,OnStartActivityResult(如上面的链接中提到的)函数接收调用并将图像保存到画廊。奇怪的是:图像被反转 180 度然后保存,这是非常奇怪的行为。
最后,这里有两个问题:用户批准前的图像预览镜像问题和保存图像反转问题(180 度反转)。
设备: Samsung A6 Edge
Android: 5.1
清单文件中的相机: Android.hardware.camera2 作为相机已弃用
请告知我如何解决上述两个问题。
另外- 我还有一个疑问:我应该使用android原生相机应用程序还是使用Camera Framework编写代码并启动自定义相机?我的要求只是单击图片并显示预览并以正确的方向保存。经过大量搜索,我很怀疑 - 原生相机应用程序可以解决这些问题吗?但是您的专家建议可以对此有所帮助。
我们非常感谢任何对此的快速支持和指导。提前致谢 ! 这是代码:
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 函数:
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;
}
}
}
【问题讨论】:
标签: android camera android-camera android-orientation android-camera-intent