我正在使用本机相机,并且图像捕获成功,但是捕获后将图像保存到图库中时,图像会旋转。我不知道该怎么办,也听从论坛上的一些指导,但是没有运气。
这是onActivityResult代码:
if (iRequestCode == TAKE_PICTURE) {
try {
if (iResultCode < 0) {
if (iResultCode == Activity.RESULT_OK) {
Bitmap picture = BitmapFactory.decodeFile(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/" +
AppConstants.AppDirectory + "/" + AppConstants.MyTempFolder + "/" + FileName);
OutputStream outputStream = null;
//create file
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + "/" +
AppConstants.AppDirectory + "/" + AppConstants.MyTempFolder, FileName);
outputStream = new FileOutputStream(file);
picture.compress(Bitmap.CompressFormat.JPEG, 50, outputStream);
//picture.recycle();
outputStream.flush();
outputStream.close();
} else {
ui.showToastMessage("No picture captured.");
}
} else {
ui.showToastMessage("No picture captured.");
}
} catch (OutOfMemoryError e) {
ui.showDialogMessage("Info", "Something went wrong.");
MyAppSLogger.appendLog("CMainActivity -> OutOfMemoryError onActivityResult(): " + e.toString());
} catch (RuntimeException e) {
ui.showDialogMessage("Info", "Something went wrong.");
MyAppSLogger.appendLog("CMainActivity -> RuntimeException onActivityResult(): " + e.toString());
} catch (Exception e) {
ui.showDialogMessage("Info", "Something went wrong.");
MyAppSLogger.appendLog("CMainActivity -> Exception onActivityResult(): " + e.toString());
} finally {
m_objMenuViews.setVisibility(View.VISIBLE);
m_objMenuViews.invalidate();
}
}
我进一步测试了。在某些设备上运行正常,但在三星j5 Prime设备上出现旋转问题。