Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

Android Camera in Portrait on SurfaceView

I tried several things to try to get the camera preview to show up in portrait on a SurfaceView. Nothing worked. I am testing on a Droid that has 2.0.1. I tried:

1) forcing the layout to be portrait by: this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

2) using

Camera.Parameters parameters = camera.getParameters();
parameters.set("orientation", "portrait");
parameters.setRotation(90);
camera.setParameters(parameters);

Is there something else I can try? If this a bug in Android or the phone how can I make sure that this is the case so that I have proof to inform the client?

Thanks, Prasanna

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As of API lvl 8, this is available:

public final void setDisplayOrientation (int degrees)

i.e. with portait in the manifest:

public void surfaceCreated(SurfaceHolder holder) {
    mCamera = Camera.open();
    mCamera.setDisplayOrientation(90);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...