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 6114335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:57:46+00:00 2026-05-23T14:57:46+00:00

I am trying to use the Camera (android.graphics.Camera not the hardware camera) to rotate

  • 0

I am trying to use the Camera (android.graphics.Camera not the hardware camera) to rotate a views canvas around a specific point, in this instance the middle of the canvas.

In dispatchDraw(Canvas canvas) — for brevity I am leaving out all the non important parts.

camera.save();
   camera.rotateX(0);
   camera.rotateY(0);
   camera.rotateZ(angle);
   camera.getMatrix(cameraMatrix);
 camera.restore(); 

 canvas.concat( cameraMatrix );

The canvas rotates, but always from the upper left hand corner.

NOTE: Because the canvas has been constructed to be larger than the display area I also need to translate the final result so that it is centered in the display, I can do this with either

canvas.translate(xOffset,yOffset) PRIOR to calling the camera methods

OR

cameraMatrix.preTranslate(xOffset,yOffset) AFTER the camera methods

Both correctly center the canvas in the display but I can’t seem to get the rotation point to be the center for the camera.rotateZ(angle) call, tried using the methods in the 3D android sample but while they seem to work for the X / Y axis them don’t seem to affect the Z axis

Any help would be appreciated, the doc’s are not exactly verbose.

  • 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-23T14:57:46+00:00Added an answer on May 23, 2026 at 2:57 pm

    Solved this, not sure if it’s the best way but it works. The solution was to

    Translate the canvas first to center the larger canvas in the display

    Then apply the camera rotations

    Then to use the pre and post translate methods on the matrix to change the rotation point similar to what the android sample did.

    The missing bits were to do the canvas translation first, and I was also not using the larger canvas size to calculate the offsets for the pre and post translate methods.

    Here is the modified code if it helps anyone else out.

    // Center larger canvas in display (was made larger so
    // corners will not show when rotated) 
    canvas.translate(-translateX, -translateY); 
    
    // Use the camera to rotate a view on any axis
    camera.save();
        camera.rotateX(0);
        camera.rotateY(0);
        camera.rotateZ(angle); // Rotate around Z access (similar to canvas.rotate)                                 
    
        camera.getMatrix(cameraMatrix);
    
        // This moves the center of the view into the upper left corner (0,0) 
        // which is necessary because Matrix always uses 0,0, as it's transform point 
        cameraMatrix.preTranslate(-centerScaled, -centerScaled);
    
        // NOTE: Camera Rotations logically happens here when the canvas has the 
        // matrix applied in the canvas.concat method 
    
        // This happens after the camera rotations are applied, moving the view 
        // back to where it belongs, allowing us to rotate around the center or 
        // any point we choose 
        cameraMatrix.postTranslate(centerScaled, centerScaled);
    camera.restore();
    
    canvas.concat(cameraMatrix);
    

    If anyone has a better way or sees a problem please leave a comment.

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

Sidebar

Related Questions

I'm trying to use gluLookAt in an Android app to move the camera around,
As part of my widget, I use an instance of the Camera object. This
I'm new to android apps development. I'm trying to use the camera of my
I'm trying to use the camera in an Android app using the 1.5 API.
I'm trying to use OpenCV to open a camera. This works fine when I
I'm trying to use new OpenCV feature on Android: native camera access. According to
I am trying to use Python to resize picture. With my camera, files are
I'm trying to modify the SurfaceView I use for doing a camera preview in
Trying to use this method (gist of which is use self.method_name in the FunnyHelper
I use android SDK 4.0.3 and eclipse Indigo and I'm trying to develop an

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.