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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:56:29+00:00 2026-06-03T06:56:29+00:00

Hi have a problem regarding rotation. I’m currently drawing a few Objects on a

  • 0

Hi have a problem regarding rotation. I’m currently drawing a few Objects on a Canvas. Currently this ‘Objects’ are just Bitmaps. After computing the rotation and passing it inside a Matrix, I’m forced to create a new Bitmap to get it rotated. A small snippet will clearify this:

public void onDraw(Canvas canvas){
    mMatrix = new Matrix();
    mMatrix.postRotate(getRotation());
    Bitmap rotateBmp = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), mMatrix, true);
    canvas.drawBitmap(rotateBmp, mCoords.x -(mBitmap.getWidth() / 2), mCoords.y - ( mBitmap.getHeight() / 2), null);
    rotateBmp.recycle();
}

All I can do to save memory is calling recycle on the rotateBmp, and it will run most of the time correctly. Lets assume I have 10 Bitmap ‘Objects’ I want to rotate. That means I have to keep ten Bitmaps as ‘sample’ and create ten new Bitmaps in every draw-cycle plus an additional new Matrix (didn’t find a way to ‘reset’ it). This sounds very weird to me. Is there another Way, to create ‘something that can be drawn on a Canvas’ on the fly (no XML), while keeping control of their rotation. Any Idea is very welcome. If its a View, a Drawable or another CustomClass doesn’t matter. Maybe it is important that getRotation will be all the same for every “Something” that should be drawn. What is the best practice to do that?

  • 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-03T06:56:30+00:00Added an answer on June 3, 2026 at 6:56 am

    With the great help of @Jason Robinson and how To Rotate Text in Canvas I figured out a Way, of how I can do it. Here is a short snippet, that will work:

    Bitmap mBitmap = getResources()...
    int xPositionOfBitmap
    int yPositionOfBitmap
    public void onDraw(Canvas canvas) {
        int bitmapCenterX = xPositionOfBitmap + (mBitmap.getWidth() / 2)
        int bitmapCenterY = yPositionOfBitmap + (mBitmap.getHeight() / 2)
        canvas.save()
        canvas.rotate(getRotation(),bitmapCenterX, bitmapCenterY)
        canvas.drawBitmap(mBitmap, xPositionOfBitmap, yPositionOfBitmap)
        canvas.restore()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem regarding the memory management when adding objects to a NSMutableArray
i have a problem regarding the responseXML of ajax.. I have this code from
I have this logical problem regarding on how to pass value from one JFrame
I have another problem regarding Git. This time I thoroughly searched Google and Stack
I have a strange problem regarding the hibernate mapping containing large objects (BLOB), when
I have this problem regarding sql which i will be using in a webservice
I have some problem regarding converting/truncating a number. This is the condition: x.35 where
I have a problem regarding GridSplitter visiblity. In this, whatever I am hosting a
I have a problem regarding this two values from my textboxes (text, text2), seems
I have a problem regarding java.lang.NoSuchMethodError. This program is about Compiler API (JSR 199).

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.