I'm developing my custom camera app and I'm having problems with the orientation.
When the phone is in portrait orientation the preview screen and result image shows in landscape
When the phone is in left landscape orientation the preview screen and result image shows correctly
When the phone is in right landscape orientation the preview screen and result image shows in landscape mode but flipped vertically
I've read about changing orientation with setDisplayorientation but I have not managed to fix it.
Can someone help me?
Thanks for the help
This is the code of the camera activity that starts preview
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
// TODO Auto-generated method stub
System.out.println("!!!!!!!CAMBIO!!!!!!!!" );
initPreview(width, height);
startPreview();
}
private void initPreview(int width, int height) {
if (myCamera!=null && mySurfaceHolder.getSurface()!=null) {
try {
myCamera.setPreviewDisplay(mySurfaceHolder);
}
catch (Throwable t) {
Log.e("PreviewDemo-surfaceCallback",
"Exception in setPreviewDisplay()", t);
Toast
.makeText(CameraHandler.this, t.getMessage(), Toast.LENGTH_LONG)
.show();
}
if (!cameraConfigured) {
Camera.Parameters parameters=myCamera.getParameters();
Camera.Size size=getBestPreviewSize(width, height,
parameters);
if (size!=null) {
parameters.setPreviewSize(size.width, size.height);
myCamera.setParameters(parameters);
cameraConfigured=true;
}
}
}
}
private void startPreview() {
if (cameraConfigured && myCamera!=null) {
myCamera.startPreview();
inPreview=true;
}
}
private Camera.Size getBestPreviewSize(int width, int height, Camera.Parameters parameters) {
Camera.Size result=null;
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
System.out.println("Soportados " + size.width + "x" + size.height);
if (size.width<=width && size.height<=height) {
if (result==null) {
result=size;
}
else {
int resultArea=result.width*result.height;
int newArea=size.width*size.height;
if (newArea>resultArea) {
result=size;
}
}
}
}
return(result);
}