使用内置相机应用程序捕获图像的方向
我已经使用意图调用了 android 2.1 中的内置相机应用程序。我使用了以下代码:
Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "MyTestFile.jpg");
cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
outputFileUri = Uri.fromFile(file);
startActivityForResult(cameraintent, CAMERA_PIC_REQUEST);
为了获取捕获的图像的方向,我使用了以下代码:
Uri capturedImage = outputFileUri;
Bitmap theBmp = MediaStore.Images.Media.getBitmap(getContentResolver(), capturedImage);
int img_orient=0;
String[] projection = { MediaStore.Images.Media.ORIENTATION };
Cursor mImageCursor = managedQuery(capturedImage, projection, null, null, null);
我无法获取捕获的照片的方向,因为光标 mImageCursor
始终为空。我的代码有什么问题?
I have invoked the built-in Camera application in android 2.1 using intent. I've used the following code:
Intent cameraintent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(Environment.getExternalStorageDirectory(), "MyTestFile.jpg");
cameraintent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
outputFileUri = Uri.fromFile(file);
startActivityForResult(cameraintent, CAMERA_PIC_REQUEST);
To get the orientation of the captured image I've used the following code:
Uri capturedImage = outputFileUri;
Bitmap theBmp = MediaStore.Images.Media.getBitmap(getContentResolver(), capturedImage);
int img_orient=0;
String[] projection = { MediaStore.Images.Media.ORIENTATION };
Cursor mImageCursor = managedQuery(capturedImage, projection, null, null, null);
I am not able to get the orientation of captured photo as the cursor mImageCursor
is always null. What is problem in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用 ExifInterface 类来读出信息。或者,照片很可能没有。某些设备会旋转照片并保存它们而不设置方向。
You could try using the ExifInterface class to read out the information instead. Alternatively, it's very possible that the photo has none. Some devices rotate the photos and save them without setting the orientation.