我有一个自定义相机应用程序,用于拍照并将它们裁剪为正方形,现在我想知道如何为最终输出图像(特别是方向)编写 Exif 数据
以下是我的代码的重要部分:
captureButton = (Button) findViewById(R.id.button_capture);
captureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Take a picture
mCamera.takePicture(null, null, mPicture);
}
});
这是回调函数:
PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
};
更新: 我在 onPictureTaken 方法中添加了以下内容,但没有任何改变:
ExifInterface exif;
exif = new ExifInterface(pictureFile.getAbsolutePath());
// Notice getOrientation method gets an Integer with the angle : 0 , 90 , 180 , 270 ..etc
exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(getOrientation()) );
exif.saveAttributes();