Android相机意图旋转问题
I'm loading the camera as an intent and saving to a local file:
Intent capturePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
capturePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriPhoto);
startActivityForResult(capturePhotoIntent, REQUEST_IMAGE_CAPTURE);
Some mobile phones are saving the image in the incorrect orientation.在照片中捕获照片中的照片,保存的图像被旋转90度到景观。
大多数手机摄像机都是景观,因此我知道这就是旋转发生的原因。相机应用程序应在EXIF数据中使用正确的方向填充图像文件。
我了解我可以使用Glide在应用程序中显示捕获的图像,这将自动为我处理旋转。
Glide.with(myContext).load(photoFilePaths.get(iPosition)).into(myViewHolder.getPhotoImageView());
但是,我相信每次加载图像时都会旋转图像 - 是否可以使用滑行将图像旋转并保存在正确的方向上,以旋转图像?
我已经看到以下内容可能是一种替代方案,但是这取决于在Exif数据中设置的正确方向:
ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
Bitmap rotatedBitmap = null;
switch(orientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
rotatedBitmap = rotateImage(bitmap, 90);
break;
...
}
public static Bitmap rotateImage(Bitmap source, float angle)
{
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
Glide在正确方向上显示图像时似乎更一致,所以我猜它遵循了另一种方法保存图像时,这可以提供更好的结果。图像需要以正确的方向上传到Web服务器,而不仅仅是在Android应用程序中显示。
I'm loading the camera as an intent and saving to a local file:
Intent capturePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
capturePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriPhoto);
startActivityForResult(capturePhotoIntent, REQUEST_IMAGE_CAPTURE);
Some mobile phones are saving the image in the incorrect orientation. Where a photo is captured with the mobile phone held in portrait, the saved image is rotated 90 degrees to landscape.
Most phone cameras are landscape, therefore I understand this is why the rotation occurs. The camera application should populate the image file with the correct orientation within the EXIF data.
I understand that I could use Glide to display the captured image within the application and this will automatically handle the rotation for me.
Glide.with(myContext).load(photoFilePaths.get(iPosition)).into(myViewHolder.getPhotoImageView());
However, I believe that this rotates the image in the ImageView each time it is loaded - could Glide be used to rotate and save the image within the correct orientation onActivityResult?
I've seen the following could be an alternative, however this relies on the correct orientation being set within the EXIF data:
ExifInterface ei = new ExifInterface(photoPath);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
Bitmap rotatedBitmap = null;
switch(orientation)
{
case ExifInterface.ORIENTATION_ROTATE_90:
rotatedBitmap = rotateImage(bitmap, 90);
break;
...
}
public static Bitmap rotateImage(Bitmap source, float angle)
{
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
Glide appears to be more consistent at displaying an image in the correct orientation, so I'm guessing it follows a different approach that could provide better results when saving the image. The image needs to be uploaded to a web server in the correct orientation, rather than just displaying within the Android application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论