图像保存方向错误 [英] Image saved with wrong orientation
问题描述
我用这code:
<一个href="https://github.com/commonsguy/cw-advandroid/blob/master/Camera/Picture/src/com/commonsware/android/picture/PictureDemo.java" rel="nofollow">https://github.com/commonsguy/cw-advandroid/blob/master/Camera/Picture/src/com/commonsware/android/picture/PictureDemo.java
凡清单
,活动方向
设置为风景
所以,它就像让用户只需要在横向模式的图片,如果图片正在通过保持设备在纵向模式下,保存的图像是这样的:
So, its like allowing user to take picture only in Landscape mode, and if the picture is taking by holding the device in portrait mode, the image saved is like this:
90度旋转的图像。
在寻找一个解决方案,我发现这一点:
After searching for a solution, I found this:
其中,解决的办法是:
在 surfaceChanged()
检查
Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
display.getRotation();
和修改相机的displayOrientation 相应。
camera.setDisplayOrientation(90);
但不管多少次,我旋转设备, surfaceChanged()
永远不会被调用。
我甚至尝试去除方向=横向
在的Manifest.xml ,但那么preVIEW本身是横盘显示(可能是因为默认 android.view.SurfaceView
应该是在风景模式?)。
I even tried removing orientation="Landscape"
in the Manifest.xml, but then the preview itself is shown sideways(may be because default android.view.SurfaceView
is supposed to be in Landscape mode?).
推荐答案
试试这个。
public void surfaceCreated(SurfaceHolder holder) {
try {
camera = Camera.open();
camParam = camera.getParameters();
Camera.Parameters params = camera.getParameters();
String currentversion = android.os.Build.VERSION.SDK;
Log.d("System out", "currentVersion " + currentversion);
int currentInt = android.os.Build.VERSION.SDK_INT;
Log.d("System out", "currentVersion " + currentInt);
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
if (currentInt != 7) {
camera.setDisplayOrientation(90);
} else {
Log.d("System out", "Portrait " + currentInt);
params.setRotation(90);
/*
* params.set("orientation", "portrait");
* params.set("rotation",90);
*/
camera.setParameters(params);
}
}
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
// camera.setDisplayOrientation(0);
if (currentInt != 7) {
camera.setDisplayOrientation(0);
} else {
Log.d("System out", "Landscape " + currentInt);
params.set("orientation", "landscape");
params.set("rotation", 90);
camera.setParameters(params);
}
}
camera.setPreviewDisplay(holder);
camera.startPreview();
} catch (IOException e) {
Log.d("CAMERA", e.getMessage());
}
}
这篇关于图像保存方向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!