Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3984866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:49:18+00:00 2026-05-20T05:49:18+00:00

I am using a Preview to display what the camera see’s on the screen.

  • 0

I am using a Preview to display what the camera see’s on the screen.

I can get everything working fine, surface created, surface set and the surface is displayed.

However it always displays the picture at an incorrect 90 degree angle in portrait mode.

Such as in the picture:

alt text

I am aware that using the following code will set the picture straight:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

However I have the Preview within an Activity that has other elements in it and it does not make sense for my Activity to be displayed in landscape mode. (Its disabled by default)

So I was wondering is there anyway to just change the orientation of the Preview? And leave the rest of my Activity correctly displayed in Portrait mode?

Or anyway to rotate the preview so that it is displayed correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T05:49:19+00:00Added an answer on May 20, 2026 at 5:49 am

    This issue appeared to start out as a bug with certain hardware see here but can be overcome by using the call to mCamera.setDisplayOrientation(degrees) available in API 8. So this is how I implement it:

    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {            
        if (isPreviewRunning) {
            mCamera.stopPreview();
        }
    
        Parameters parameters = mCamera.getParameters();
        Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
    
        if(display.getRotation() == Surface.ROTATION_0) {
            parameters.setPreviewSize(height, width);                           
            mCamera.setDisplayOrientation(90);
        }
    
        if(display.getRotation() == Surface.ROTATION_90) {
            parameters.setPreviewSize(width, height);                           
        }
    
        if(display.getRotation() == Surface.ROTATION_180) {
            parameters.setPreviewSize(height, width);               
        }
    
        if(display.getRotation() == Surface.ROTATION_270) {
            parameters.setPreviewSize(width, height);
            mCamera.setDisplayOrientation(180);
        }
    
        mCamera.setParameters(parameters);
        previewCamera();                      
    }
    
    And the previewCamera method :
    
    public void previewCamera() {        
        try {           
            mCamera.setPreviewDisplay(mSurfaceHolder);          
            mCamera.startPreview();
            isPreviewRunning = true;
        } catch(Exception e) {
            Log.d(APP_CLASS, "Cannot start preview", e);    
        }
    }
    

    This was on an HTC Desire and I had to initially put in logging statements in each of the rotation checks to say what the rotation was and then debugged on the device and watched the logCat output while I rotated the device. For the HTC Desire, 0 was the phone as you would have expected (portrait), 90 degrees was turning the phone 90 degrees COUNTER-CLOCKWISE (I had assumed it would have been clockwise). In the code you’ll see I didn’t need to do any display rotation when the phone was at 90 or 180 degrees – the device seemed to handle this itself. Only one point not working properly: The 270 degree rotation is when you turn the device 90 degrees clockwise and the display rotation counters that ok but if you rotate the device 270 degrees counter-clockwise, it doesn’t appear to compensate it properly.

    P.S. Note the swapover of width and height in the appropriate rotations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display a filtered camera preview, using onPreviewFrame() callback. The problem
Using an Android (2.3.3) phone, I can use the camera to retrieve a preview
I'm using a PictureListBox to display some thumbnails for picture preview. The pictures I
I preview docs in my app using a UIDocumentInteractionController. However, sometimes documents show fine,
Some apps display an Add a caption in the Preview Screen after taking/selecting an
I am working on a very simple application, using MVC2 Preview 1. I have
I am using this script to display an image preview for users when they
I'm trying to display an image on top of a surface where a camera
I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a
I'm using Camera API and invoking the camera. I want to display a header

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.