4
我面臨一個問題,試圖在縱向模式下進行相機預覽。我讀過關於它的各種文章和我已經解決了具有下面的代碼是:安卓相機setDisplayOrientation:奇怪的星系標籤行爲
Display display = ((CaptureActivity)context).getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
if (Integer.parseInt(Build.VERSION.SDK) >= 8) {
setDisplayOrientation(camera, 90);
}else{
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
camera.setParameters(parameters);
}
其中作爲setDisplayOrientation()的定義是:
protected void setDisplayOrientation(Camera camera, int angle) {
Method downPolymorphic;
try {
downPolymorphic = camera.getClass().getMethod(
"setDisplayOrientation", new Class[] { int.class });
if (downPolymorphic != null)
downPolymorphic.invoke(camera, new Object[] { angle });
} catch (Exception e1) {
}
}
現在,我想這個代碼到的Galaxy Tab,它失敗。我解決了它(嘗試和錯誤的做法),使用下面的代碼:
if (height == 1024 && width == 600) {
Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.setRotation(90);
camera.setParameters(parameters);
}
現在我的兩個問題是:
1)爲什麼有這樣的問題,而Galaxy Tab的具有2.2版本,並
2)有沒有更好的解決方案來解決這個問題?
非常感謝您的時間!
你檢查了這個解決方案:http://stackoverflow.com/questions/3841122/android-camera-preview-is-sideways/5110406#5110406 –
Yeap,沒有運氣......非常感謝! –
@DimitrisMakris你有沒有得到任何解決方案。請!分享,我面對同一個? – swiftBoy