use*_*045 6 android exif orientation
setRotation methodin Camera.Parameters不适用于所有设备.有人建议手动更改EXIF信息以解决问题.你能给我一个关于如何设置exif信息的简短例子,ExifInterface以这种方式将图像方向设置为肖像吗?
private int savePicture(byte[] data)
{
File pictureFile = getOutputMediaFile();
if (pictureFile == null)
return FILE_CREATION_ERROR;
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
return FILE_NOT_FOUND;
} catch (IOException e) {
return ACCESSING_FILE_ERROR;
}
return OKAY;
}
Run Code Online (Sandbox Code Playgroud)
我试过这个:
try {
ExifInterface exifi = new ExifInterface(pictureFile.getAbsolutePath());
exifi.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(ExifInterface.ORIENTATION_ROTATE_90));
exifi.saveAttributes();
} catch (IOException e) {
Log.e(TAG, "Exif error");
}
Run Code Online (Sandbox Code Playgroud)
但是当我从android画廊想象出图片时没有任何改变.
对于那些真正想要写出这些EXIF信息的人,这里有一些代码:
ExifInterface exifInterface = new ExifInterface(someFile.getPath());
exifInterface.setAttribute(ExifInterface.TAG_ORIENTATION,
String.valueOf(orientation));
exifInterface.saveAttributes();
Run Code Online (Sandbox Code Playgroud)
而是orientation标准方向之一,即ExifInterface.ORIENTATION_ROTATE_{90,180,270}.
好吧,我陷入了此类问题,并尝试了您正在研究的解决方案,最终使用了 Matrix 函数。
无论我拍摄什么图像,都是风景,所以在应用程序中我只需应用以下代码,效果很好:-
Matrix matrix = new Matrix();
//set image rotation value to 90 degrees in matrix.
matrix.postRotate(90);
//supply the original width and height, if you don't want to change the height and width of //bitmap.
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0, newWidth, newHeight, matrix, true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19824 次 |
| 最近记录: |