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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:57:56+00:00 2026-06-12T09:57:56+00:00

I have a problem to rotate bitmap on canvas ,I am drawing bitmap on

  • 0

I have a problem to rotate bitmap on canvas ,I am drawing bitmap on canvas by using canvas.drawline and use following code to rotate image

It rotate but it shows two image now ?How to remove previous image from canvas? What to do?

bitmap = Bitmap.createBitmap((int) /*getWindowManager()
                        .getDefaultDisplay().getWidth()*/600, (int) /*getWindowManager()
                        .getDefaultDisplay().getHeight()*/600, Bitmap.Config.ARGB_8888 );
             Canvas canvas = new Canvas(bitmap);
             drawingImageView.setVisibility(View.VISIBLE);

               drawingImageView.setImageBitmap(bitmap);

              // canvas.rotate(90);
                   for(int i=0;i<SettingsStaticData.arrX1_crossPoint.size();i++)
                   {

                       canvas.drawLine(new Float(SettingsStaticData.arrX1_crossPoint.get(i)),new Float(SettingsStaticData.arrY1_crossPoint.get(i)),new Float(SettingsStaticData.arrX2_crossPoint.get(i)) ,new Float(SettingsStaticData.arrY2_crossPoint.get(i)), paint);


                   }


                    paint.setStrokeWidth((float) 0.9);
                   paint.setStyle(Paint.Style.FILL);
                 //  paint.setColor(Color.RED);

                   paint.setColor(Color.parseColor("#800080"));
               for(int i=0;i<arrXX.size()-1;i++)
                {

                  if(i==arrXX.size()-2)
                  {
                      canvas.drawLine(new Float(arrXX.get(0)),new Float(arrYY.get(0)),new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);
                      canvas.drawLine(new Float(arrXX.get(i)),new Float(arrYY.get(i)),new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);

                  }
                  else
                  {
                      canvas.drawLine(new Float(arrXX.get(i)),new Float(arrYY.get(i)),new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);

                  }
                }


        //     canvas.drawColor(0, Mode.CLEAR);
               Matrix matrix = new Matrix();

                  matrix.reset();
               matrix.postTranslate(-bitmap.getWidth() / 2-500, -bitmap.getHeight() / 2-500); // Centers image
               matrix.postRotate(180);
              //matrix.postTranslate(px, py);


               canvas.drawBitmap(bitmap, matrix, null);
  • 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-12T09:57:58+00:00Added an answer on June 12, 2026 at 9:57 am

    The problem is the last line: canvas.drawBitmap(bitmap, matrix, null);

    canvas is initialized with the bitmap so you draw the bitmap on itself (with some changes).

    Just create another Canvas canvas2 and change the last line to canvas2.drawBitmap(bitmap, matrix, null); and display the last one drawingImageView.setImageBitmap(bitmap2); where bitmap2 is the bitmap used to create canvas2.

    So, explicitly:

    bitmap = Bitmap.createBitmap((int) /*getWindowManager()
                .getDefaultDisplay().getWidth()*/600, (int) /*getWindowManager()
                .getDefaultDisplay().getHeight()*/600, Bitmap.Config.ARGB_8888 );
    bitmapFinal = Bitmap.createBitmap((int) /*getWindowManager()
                .getDefaultDisplay().getWidth()*/600, (int) /*getWindowManager()
                .getDefaultDisplay().getHeight()*/600, Bitmap.Config.ARGB_8888 );
    
        Canvas canvas = new Canvas(bitmap);
        // canvas.rotate(90);
        for(int i=0;i<SettingsStaticData.arrX1_crossPoint.size();i++){
            canvas.drawLine(new Float(SettingsStaticData.arrX1_crossPoint.get(i)),
                    new Float(SettingsStaticData.arrY1_crossPoint.get(i)),
                    new Float(SettingsStaticData.arrX2_crossPoint.get(i)) ,
                    new Float(SettingsStaticData.arrY2_crossPoint.get(i)), paint);
        }
    
        paint.setStrokeWidth((float) 0.9);
        paint.setStyle(Paint.Style.FILL);
        //  paint.setColor(Color.RED);
    
        paint.setColor(Color.parseColor("#800080"));
        for(int i=0;i<arrXX.size()-1;i++){
    
            if(i==arrXX.size()-2){
                canvas.drawLine(new Float(arrXX.get(0)),new Float(arrYY.get(0)),
                        new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);
                canvas.drawLine(new Float(arrXX.get(i)),new Float(arrYY.get(i)),
                        new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);
    
            }else{
                canvas.drawLine(new Float(arrXX.get(i)),new Float(arrYY.get(i)),new Float(arrXX.get(i+1)) ,new Float(arrYY.get(i+1)), paint);
            }
        }
        //     canvas.drawColor(0, Mode.CLEAR);
        Matrix matrix = new Matrix();
        matrix.reset();
        matrix.postTranslate(-bitmap.getWidth() / 2-500, -bitmap.getHeight() / 2-500); // Centers image
        matrix.postRotate(180);
        //matrix.postTranslate(px, py);
    
        Canvas canvas2 = new Canvas(bitmapFinal);
        canvas2.drawBitmap(bitmap, matrix, null);
        drawingImageView.setVisibility(View.VISIBLE);
        drawingImageView.setImageBitmap(bitmapFinal);
    

    Also, my advice is to look for a better place to create the bitmaps – you don’t really need to create a new bitmap every time – you should create them once and reuse (it is expensive to continually create bitmaps). I would sugest onCreate() function for this purpose.

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

Sidebar

Related Questions

Good day, I have weird problem with drawing image. Code and pictures say more
I'm having a problem getting a bitmap to rotate properly. I have a SurfaceView
I have a problem when rendering cubes in OpenGL.I am drawing two cubes, one
I have a problem with rotate animation. I want my image to stop where
I am trying to rotate a bitmap when drawing it to a canvas. The
I have problem when using modalPresentationStyle. I call the following function in my tabbarcontroller's
I need to solve a problem by rotating an image, but I have this
I have a problem with rotating. I know that I can rotate a Texture2D
I have a great problem about the rotation in three.js I want to rotate
I have problem with my query on C, I’m using the oci8 driver. This

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.