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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:16:41+00:00 2026-06-13T09:16:41+00:00

I am drawing a text on android canvas using the following piece of code

  • 0

I am drawing a text on android canvas using the following piece of code

        Rect rect = new Rect();
        paint.getTextBounds(text, 0, text.length(), rect);
        canvas.translate(xPosition + position.getX(), yPosition + position.getY());
        paint.setColor(Color.BLUE);
        paint.setStyle(Style.STROKE);
        canvas.drawRect(rect, paint);
        paint.setStyle(Style.FILL);
        paint.setColor(text_color);
        canvas.translate(-(xPosition + position.getX()), -(yPosition + position.getY()));
        canvas.rotate(getDegreesFromRadians(angle), xPosition + position.getX() + rect.exactCenterX(), yPosition + position.getY() + rect.exactCenterY());
        canvas.drawText(text, xPosition + position.getX(), yPosition + position.getY(), paint);

This code takes care of the rotation of the text and it works fine. I am drawing a blue rectangle around the text using the above code. Now my problem is that the rectangle is not rotating along with the text. It still remains the same. Is there any way to rotate the rectangle drawn in android canvas?

  • 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-13T09:16:42+00:00Added an answer on June 13, 2026 at 9:16 am

    I found my own answer. I used the following code

    Rect rect = new Rect();
            paint.setColor(text_color);
            paint.setStyle(Style.FILL);
            paint.getTextBounds(text, 0, text.length(), rect);
            canvas.translate(xPosition + position.getX(), yPosition + position.getY());
            canvas.translate(-(xPosition + position.getX()), -(yPosition + position.getY()));
            canvas.rotate(getDegreesFromRadians(angle), xPosition + position.getX() + rect.exactCenterX(), yPosition + position.getY() + rect.exactCenterY());
            canvas.drawText(text, xPosition + position.getX(), yPosition + position.getY(), paint);
            paint.getTextBounds(text, 0, text.length(), rect);
            canvas.translate(xPosition + position.getX(), yPosition + position.getY());
            paint.setColor(Color.BLUE);
            paint.setStyle(Style.STROKE);
            paint.setStrokeWidth(4);
            rect = new Rect(rect.left - 10, rect.top - 10, rect.right + 10, rect.bottom + 10);
            canvas.drawRect(rect, paint);
    

    The thing is the whole canvas is being rotated for rotating the text. So i just need to draw the rectangle after the rotation of the canvas.

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

Sidebar

Related Questions

I'm drawing simple text in HTML5 canvas using this: context.fillStyle = #FF0000 context.font =
I am developing a program drawing text on screen using android NDK in C
I'm drawing text in VB.net by using: gfx.DrawString(_bText, New Font(Tahoma, 5), Brushes.Black, New Point(25,
I am very new to Java and android. my 1st app using canvas and
I am trying to scroll my textview using the following code: TextView text =
i am drawing text on canvas using drawText() method.But when line is bigger then
I'm drawing text in an HTML5 canvas on top of an image (a meme
I use this code for drawing text in a panel: Graphics g = panel1.CreateGraphics();
I am searching about drawing bordered text on UIView. Implemented following method : -
I am drawing text on TCanvas using TextOut() but I want bigger fonts. What

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.