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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:22:46+00:00 2026-05-29T09:22:46+00:00

I am working on a game in Android and I have Bitmap objects being

  • 0

I am working on a game in Android and I have Bitmap objects being drawn. They are rotated using the Matrix class. The problem I am having is being able to access the pixels of the rotated Bitmap. When I access them after rotation the pixels are still representing the unrotated version. Does anyone have any ideas? Maybe I can rotate the pixel array based on an arbitrary number of degrees? I have seen solutions that create a new bitmaps on the fly based on the newly rotated images, but I can’t do this because of performance issues. Thanks!

Here is how I draw the bitmap currently (The bitmap is drawn using the matrix as its position)…

canvas.drawBitmap(bitmapPlayer, positionMatrix, null);

Here is how I create the positionMatrix variable…

Matrix m = new Matrix();
m.postRotate(degrees, bitmapCenterX, bitmapCenterY);
positionMatrix.set(m);

Here is how I access the pixels currently (This accesses the pixel array I created below)…

getPixel(x, y);

Here is how I build the pixel array that I have tried to modify…

// Build pixel 2d array
pixelData = new int[bitmapPlayer.getWidth()][bitmapPlayer.getHeight()];

for(int x=0; x<bitmapPlayer.getWidth(); x++) {
    for(int y=0; y<bitmapPlayer.getHeight(); y++) {
        pixelData[x][y] = bitmapPlayer.getPixel(x, y);
    }
}

Here is how I have tried to manipulate the array…

public void rotatePixels(int degrees) {
    int[][] newPixelData = new int[bitmapPlayer.getWidth()][bitmapPlayer.getHeight()];

    double cos = Math.cos(Math.toRadians(degrees));
    double sin = Math.sin(Math.toRadians(degrees));

    for(int x=0; x<bitmapPlayer.getWidth(); x++) {
        for(int y=0; y<bitmapPlayer.getHeight(); y++) {
            if(pixelData[x][y] != 0) {
                int currentX = x + getTopLeftX();
                int currentY = y + getTopLeftY();

                int nextX = (int)((currentX * cos) - (currentY * sin));
                int nextY = (int)((currentX * sin) + (currentY * cos));

                if(nextX >= 0 && nextX < bitmapPlayer.getWidth() && nextY >= 0 && nextY < bitmapPlayer.getHeight()) {
                      newPixelData[nextX][nextY] = 1;
                }
            }
        }
    }

    this.pixelData = newPixelData;
}
  • 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-29T09:22:47+00:00Added an answer on May 29, 2026 at 9:22 am

    Have you tried:

    Matrix mat = new Matrix();
    mat.postRotate(45);
    Bitmap newBm = Bitmap.createBitmap(bitmapPlayer, 0, 0, bitmapPlayer.width(), bitmapPlayer.height(), mat, true);
    

    and then accessing the pixels of the new Bitmap?

    I think right now you just draw a rotated bitmap on the canvas, you’re not actually rotating the bitmap

    EDIT:

    The way you do it in your orinigal post won’t work because you start at (0,0) and work your way down the left column… Depending on the rotation degree you’d have to start at a different place and then go down a different column. i.e. a small ctrclkwise rotation and you start at the top right index.

    Bitmap bm = someImage;
    int startx, starty;
    int degree = rotateDegree % 360; // counterclockwise
    if (degree >= 0 && degree < 90) {
        startx = bm.getWidth();
        starty = 0;
    } else if (degree >= 90 && degree < 180) {
        startx = bm.getWidth();
        starty = bm.getWidth();
    } else if (degree >= 180 && degree < 270) {
        startx = 0();
        starty = bm.getWidth();
    } else {
        startx = 0;
        starty = 0;
    }
    

    And then try traversing the image that way, starting at (startx, starty)
    and adding or subtracting the correct angle (you can use some boolean to keep track
    of whether you’re adding or subtracting from x or y respectively). Let me know if this works,
    and if it doesn’t can you be a little more specific about where you think the problem might be?

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

Sidebar

Related Questions

I'm working on a game (using Ruby) and planning to have it available in
Ahoy, I'm working on an OpenGL ES based game for Android using the NDK.
I have a been working on a game for Android and debugging it on
I have been working on an Android game for the past 6 months or
I'm working on a 2D game for android using OpenGL ES 1.1 and I
I'm porting a game from WP7 XNA to Android; everything was working using Canvas
Hi I'm new to android development and working on a game. I currently have
So I am working on an Android game and I have two images on
I'm working on a game engine in C++ and I have methods like setColour
I'm currently developing a simple 2D game for Android. I have a stationary object

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.