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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:31:03+00:00 2026-06-11T05:31:03+00:00

Good evening. I’m trying to rotate a line on a canvas using setRotation -method

  • 0

Good evening.

I’m trying to rotate a line on a canvas using setRotation -method and it works perfectly, unless you want to draw another shape on the same canvas. After using Canvas’s concat -method, the entire canvas will be rotated, let’s say, by 30 degrees counterclockwise/clockwise. And this is the problem. I would like to rotate only the line and I don’t want to rotate any other shapes on this canvas or the entire canvas. I found out that the bitmap could be drawn with matrices, but it looks cumbersome and clumsy. Also, there was a suggestion to setup a new matrix for the Canvas, in fact, this proposition works neither.

So, the question sounds simple enough, how could the only one shape on the canvas be rotated without using OpenGl and affecting on other shapes on the canvas?

Thank you for your answers in advance!

Here is the code with comments and other stuff:

@Override
public void onDraw(Canvas canvas)
{
    int startX, startY, stopX, stopY;
    startY = stopY = 100;
    startX = 100;
    stopX = 200;
    this.paint = new Paint();
    //this.path = new Path();
    this.matrix = canvas.getMatrix();
    this.paint.setColor(Color.BLUE);
    this.paint.setStrokeWidth(4);

    this.matrix.setRotate(180, startX, startY);
    canvas.concat(this.matrix);
    /*this.matrix.setTranslate(startX, 0);
    canvas.concat(this.matrix);*/

    canvas.drawLine(startX, startY, stopX, stopY, this.paint);

    canvas.setMatrix(new Matrix());
    //canvas.drawCircle(200, 200, 50, paint);
}
  • 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-11T05:31:04+00:00Added an answer on June 11, 2026 at 5:31 am

    You could try Canvas.save() and Canvas.restore() for this. They supposedly put current matrix into stack and you can return back to previous one once done with the modified matrix.

    this.matrix.setRotate(180, startX, startY);
    canvas.save();
    canvas.concat(this.matrix);
    canvas.drawLine(startX, startY, stopX, stopY, this.paint);
    canvas.restore();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good Evening, I'm using this script, it works really good but I want it
Good evening, experts I want to solve recurrence equation using mathematica, x(n) = x(n
Good evening! I want to display a uncommon layout into a HTML Textfield, using
Good evening, I am having a weird issue with a method I am trying
Good evening all, I'm trying to write a method that creates and returns a
Good evening guys. I'm currently trying to get started on development of a project
Good evening guys, I'm trying to pass multiple checkbox values through AJAX and process
Good evening, I am trying to generalize the histogram filter localization to discrete environments
Good evening everyone, I am using a JavaScript to load/override content from an HTML-File
Good Evening, I'm using Drupal 6, CCK Module, and the Link Field Type. All

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.