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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:48:50+00:00 2026-05-31T08:48:50+00:00

I am trying to rotate a bitmap using the code below. The code works

  • 0

I am trying to rotate a bitmap using the code below.

The code works fine on emulator (although the infinite rotation has a small lag but that’s another story) but when tested on the actual device the rotation is wrong (wrong pivot I think).

I appreciate any help.

G

public class CircleAnimation extends View {

Bitmap bitmap;
Paint paint;
RotateAnimation rotate;
AlphaAnimation blend;
ScaleAnimation scale;
AnimationSet spriteAnimation;

float centerX;
float centerY;
float offsetX;
float offsetY;

public CircleAnimation(Context context) {
      super(context);
      // TODO Auto-generated constructor stub

      bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tile);
        offsetX = bitmap.getWidth() / 2;
        offsetY = bitmap.getHeight() / 2;

        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
}

@Override
protected void onDraw(Canvas canvas){
    //Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tile);
    //canvas.drawBitmap(myBitmap, 0, 0, null);
    super.onDraw(canvas);

    if (spriteAnimation == null) {
        centerX = canvas.getWidth() / 2;
        centerY = canvas.getHeight() / 2;
        createAnimation(canvas);
    }
    canvas.drawBitmap(bitmap, centerX - offsetX, centerY - offsetY, paint);
}

private void createAnimation(final Canvas canvas) {

    rotate = new RotateAnimation(0, 360, centerX, centerY);
    rotate.setRepeatCount(Animation.INFINITE);
    rotate.setInterpolator(new LinearInterpolator());
    rotate.setStartOffset(0);

    spriteAnimation = new AnimationSet(true);
    spriteAnimation.addAnimation(rotate);
    spriteAnimation.setDuration(1000);

    startAnimation(spriteAnimation);

}

}

  • 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-31T08:48:52+00:00Added an answer on May 31, 2026 at 8:48 am

    Ok I found the problem.

    I had set the minimum SDK to 8 and target SDK to 8 as well. And I was testing on 15.

    Changed the target to 15 and it worked.

    :p

    G

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

Sidebar

Related Questions

I'm trying to rotate a camera image. The code looks like that: Bitmap result
I'm trying to rotate a UIView object like shown on the image below http://i.piccy.info/i7/f8ff7fe488c7c492e6ff6a689bc9cdeb/1-5-2127/60800682/rotation.png
I'm trying to rotate a rectangle by rotating its points , using this code
I'm trying to rotate an image around the center. This works generally using RotateAnimation,
I'm trying to rotate and then scale an image using android.graphics.Matrix. The code is
I'm trying to rotate a bitmap 90 degrees using the following function. The problem
I am trying to rotate out an innoDB table which has a high number
I am trying to rotate an image in OpenCV. I've used this code that
Basically what I'm trying to do is have a picture rotate using mouse events.
I'm trying to rotate a bitmap image clockwise 90 degree. I've tried changing 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.