I have a custom camera activity which is supposed to take pictures in portrait mode only, however in Samsung devices the pictures always turns out in landscape mode on my nexus device the picture is displaying correctly in portrait mode. Below is my method for setting the camera parameters and orientation. This initPreview is called in the SurfaceHolder.Callback
surfaceChanged
method.
/** INITIALIZE THE PREVIEW PARAMTERS */
private void initPreview(int width, int height) {
if ( mCamera != null && previewHolder.getSurface() != null) {
try {
mCamera.setPreviewDisplay( previewHolder );
}
catch (Throwable t) {
Log.e("PreviewDemo-surfaceCallback", "Exception in setPreviewDisplay()", t);
Crouton.makeText( this, t.getMessage(), Style.ALERT ).show();
}
if (!cameraConfigured) {
Camera.Parameters parameters = mCamera.getParameters();
Camera.Size size = getBestPreviewSize(width, height, parameters);
Camera.Size pictureSize = getSmallestPictureSize(parameters);
if (size != null && pictureSize != null) {
parameters.setPreviewSize( size.width, size.height );
parameters.setPictureSize( pictureSize.width, pictureSize.height );
parameters.setPictureFormat( ImageFormat.JPEG);
parameters.set( "orientation", "portrait" );
parameters.setRotation( 90 );
mCamera.setDisplayOrientation( 90 );
mCamera.setParameters( parameters );
cameraConfigured = true;
}
}
}
}