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

  • Home
  • SEARCH
  • 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 8692415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:18:33+00:00 2026-06-13T00:18:33+00:00

I am creating an app in android in which user will be able to

  • 0

I am creating an app in android in which user will be able to take a picture from front camera in portrait mode only. I have achieved fixing the camera view to portrait but when a picture is taken it appears rotated. The worst thing is that the direction of rotation is different in different phones, in one phone it is right rotated whereas in another it is left rotated.

Here is my code snippets

To make sure activity plays in portrait only

 <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" 
             android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

To fetch camera

   @Override
  public void onResume() {
    super.onResume();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
      Camera.CameraInfo info=new Camera.CameraInfo();

      for (int i=0; i < Camera.getNumberOfCameras(); i++) {
        Camera.getCameraInfo(i, info);

        if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
          camera=Camera.open(i);
        }
      }
    }

    if (camera == null) {
      camera=Camera.open();
    }
  }

To rotate camera

    @Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
    if(previewing){
        camera.stopPreview();
        previewing = false;
    }

    if (camera != null){
        try {
            camera.setPreviewDisplay(surfaceHolder);
            camera.setDisplayOrientation(90);
            initPreview(width, height);
            startPreview();

            previewing = true;
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

Picture taken

     PictureCallback myPictureCallback_JPG = new PictureCallback(){

    @Override

     public void onPictureTaken(byte[] data, Camera arg1) {
         // new SavePhotoTask().execute(data);
        Intent myIntent = new Intent(MainActivity.this, CropActivity.class);
        Bitmap bitmap = BitmapFactory.decodeByteArray(data , 0, data .length);
        myIntent.putExtra("image", bitmap);
        MainActivity.this.startActivity(myIntent);

     }};

The BMP send is always appearing in rotated form, but not always with 90 degree. It looks like android 4.0 not only rotates but flips the image as well. Is there a good way to detect and make sure I always get correct picture?

  • 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-06-13T00:18:34+00:00Added an answer on June 13, 2026 at 12:18 am

    The issue with mirror and flip was figured out to be specific to android 4.0+, So this worked

    Matrix rotateRight = new Matrix();
    rotateRight.preRotate(90);
    
    if(android.os.Build.VERSION.SDK_INT>13 && CameraActivity.frontCamera)
    {
        float[] mirrorY = { -1, 0, 0, 0, 1, 0, 0, 0, 1};
        rotateRight = new Matrix();
        Matrix matrixMirrorY = new Matrix();
        matrixMirrorY.setValues(mirrorY);
    
        rotateRight.postConcat(matrixMirrorY);
    
        rotateRight.preRotate(270);
    
    }
    
    final Bitmap rImg= Bitmap.createBitmap(img, 0, 0,
                    img.getWidth(), img.getHeight(), rotateRight, true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an app for android which will be used by gym members.
I am creating an android app which pulls in RSS Feeds from here http://spaceflight1.nasa.gov/realdata/sightings/cities/rss/index.cgi?country=United_Kingdom&region=England&city=Manchester
I'm creating an android app which will call a method which parses the selected
I'm creating an Android app which must do some web surfing in the background
I'm creating a gallery section for my app which will be used to show
I am creating an Android app that will download and cache PDF files (the
i am creating app which would download and save files, than user could use
I have to develop an android app for which I have to use camera
I am creating an iOS and Android app. The app will track the same
I am new in android development.I am creating an android app in which the

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.