I had a problem trying to view the camera in portrait mode. I read various articles about this, and I decided that it has the following code:
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); }
where setDisplayOrientation () is defined as:
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) { } }
Now I tried this code on the Galaxy tab and it failed. I solved this (attempt and error approach) using the following code:
if (height == 1024 && width == 600) { Camera.Parameters parameters = camera.getParameters(); parameters.set("orientation", "portrait"); parameters.setRotation(90); camera.setParameters(parameters); }
Now my two questions:
1) Why is there such a problem, while the Galaxy tab has version 2.2, and
2) Is there a better solution to this problem?
Thanks so much for your time!
source share