ポートレート モードでカメラのプレビューを表示しようとすると、問題が発生します。それに関するさまざまな記事を読みましたが、次のコードで解決しました。
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);
}
今私の2つの質問は次のとおりです。
1) Galaxy タブのバージョンが 2.2 なのになぜこのような問題が発生するのか、および
2) この問題に対するより良い解決策はありますか?
ありがとうございました!