5
私はアンドロイドタブレットをコーディングしています。私は自分のアプリがsurfaceView
カメラプレビューのポートレートビューを使用したいと思っています。これは、デフォルトでは風景である、と私はポートレートビューに回転させるために、次のコードを試してみました:faceviewでAndroidカメラをポートレートに変更するにはどうすればよいですか?
public void surfaceCreated(SurfaceHolder holder){
// The Surface has been created, acquire the camera and tell it where to draw.
mCamera = Camera.open();
Parameters params = mCamera.getParameters();
// If we aren't landscape (the default), tell the camera we want portrait mode
if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE){
params.set("orientation", "portrait"); // "landscape"
// And Rotate the final picture if possible
// This works on 2.0 and higher only
//params.setRotation(90);
// Use reflection to see if it exists and to call it so you can support older versions
try {
Method rotateSet = Camera.Parameters.class.getMethod("setRotation", new Class[] { Integer.TYPE });
Object arguments[] = new Object[] { new Integer(270) };
rotateSet.invoke(params, arguments);
} catch (NoSuchMethodException nsme) {
// Older Device
Log.v("CameraView","No Set Rotation");
} catch (IllegalArgumentException e) {
Log.v("CameraView","Exception IllegalArgument");
} catch (IllegalAccessException e) {
Log.v("CameraView","Illegal Access Exception");
} catch (InvocationTargetException e) {
Log.v("CameraView","Invocation Target Exception");
}
}
mCamera.setParameters(params);
try{
mCamera.setPreviewDisplay(holder);
} catch (IOException exception) {
mCamera.release();
mCamera = null;
}
}
しかし、それは動作しません。誰もそれを修正できますか?カメラparams.set("orientation"...
のものを使用して
public void surfaceCreated(SurfaceHolder holder) {
if (Build.VERSION.SDK_INT >= 8) mCamera.setDisplayOrientation(90);
}
デバイス間で一貫していないと、本当に事前SDK 8言語で次のように
また、オブジェクト引数[] = new Object [] {new Integer(90)}で試行しました。それでも私はそれを修正することができませんでした。 –
サーフェスビューが機能するようになったので、私に例を教えてください。私はipcameraからアンドロイドにストリームする必要があり、私はサーフェイスビューを使用したい – Lily