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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:16:23+00:00 2026-05-22T20:16:23+00:00

I have overridden the onDraw() method as follows: public void onDraw(Canvas canvas1){ Canvas canvas2

  • 0

I have overridden the onDraw() method as follows:

public void onDraw(Canvas canvas1){
Canvas canvas2 = new Canvas();

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.graphic1);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.graphic2);

canvas1.drawBitmap(
          top,
          new Rect(0, 0, graphic1.getWidth(), graphic1.getHeight()),
          new Rect(0, 0, width, width),
          null);

canvas2.drawBitmap(
          top,
          new Rect(0, 0, graphic2.getWidth(), graphic2.getHeight()),
          new Rect(0, 0, width, width),
          null);

}

Only graphic1 on canvas1 gets displayed, canvas2 and graphic2 do not. How can i get multiple canvases to be displayed on a single view?

  • 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-22T20:16:24+00:00Added an answer on May 22, 2026 at 8:16 pm

    As the comment said you’re not attaching Canvas2 to anything. You’re creating it each frame (which is bad), drawing to it and then letting it go our of scope to be garbage collected. What you should do it create Canvas2 with a backing Bitmap in the constructor of your view and keep it as a member. Then you can draw to it and then blit its Bitmap to Canvas1. For example:

    public MyCustomView(Context context)
    {
        super(context);
        _canvas2 = new Canvas(_backingBitmap);
    }
    
    public void onDraw(Canvas canvas1)
    {
    Bitmap graphic1 = BitmapFactory.decodeResource(getResources(), R.drawable.graphic1);
    Bitmap graphic2 = BitmapFactory.decodeResource(getResources(), R.drawable.graphic2);
    
    canvas1.drawBitmap(
              top,
              new Rect(0, 0, graphic1.getWidth(), graphic1.getHeight()),
              new Rect(0, 0, width, width),
              null);
    
    _canvas2.drawBitmap(
              top,
              new Rect(0, 0, graphic2.getWidth(), graphic2.getHeight()),
              new Rect(0, 0, width, width),
              null);
    
    canvas1.drawBitmap(
              top,
              new Rect(0, 0, _backingBitmap.getWidth(), _backingBitmap.getHeight()),
              new Rect(0, 0, width, width),
              null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following on Draw method: @Override protected void onDraw(Canvas canvas) { //
friends, i am using following onDraw method to display bitmap on screen. @Override public
I have a class that extends View and overrides the onDraw(Canvas canvas) method. This
I have a view that I have overridden the onDraw method to output the
I have succesfully extended a view and overridden the onDraw() method I can draw
How can I draw an ImageView from the OnDraw() method? canvas.() does not have
I have a class that extends View. I override the onDraw method and allow
I have a class that derives from ImageView . In its onDraw method override
I have overridden my back button method and I want to know, when at
I have created a custom ImageView and in its onDraw method I need to

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.