I am encoding an Android tablet and want my application to use portrait camera preview surfaceView. By default, this is a landscape, and I tried the following code to rotate into portrait view:
public void surfaceCreated(SurfaceHolder holder){
mCamera = Camera.open();
Parameters params = mCamera.getParameters();
if (this.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE){
params.set("orientation", "portrait");
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) {
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;
}
}
But that will not work. Can anyone fix it?
source
share