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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:53:34+00:00 2026-05-14T03:53:34+00:00

I have a problem with the following code: protected void onDraw(Canvas canvas) { Paint

  • 0

I have a problem with the following code:

protected void onDraw(Canvas canvas)
{
    Paint paint = new Paint();

    // Draw a blue circle
    paint.setColor(Color.BLUE);
    canvas.drawCircle(100, 100, 50, paint);

    // Draw a red circle where it collides with the blue one
    paint.setXfermode(new AvoidXfermode(Color.BLUE, 0, Mode.TARGET));
    paint.setColor(Color.RED);
    canvas.drawCircle(50, 50, 50, paint);
}

According to the API documentation of AvoidXfermode the tolerance value 0 means that it looks for an EXACT color match. This should work here because I specify the same color as I used for drawing the first circle. But the result is that the red circle is not drawn at all. When I use a tolerance value of 255 instead then it works (red circle is drawn where it collides with the blue one) but that sounds wrong because with such a high tolerance I think it should draw the circle EVERYWHERE.

So what’s wrong here? API Documentation? Android? Me?

  • 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-14T03:53:34+00:00Added an answer on May 14, 2026 at 3:53 am

    Is your canvas bit depth RGB_565 or ARGB_8888? I tested this on both formats. It worked on a 32-bit canvas, but did not work on the 16-bit canvas. The 16-bit image is likely unable to display the exact color you are drawing(0xFF0000FF), so it gets changed oh so slightly (and imperceptibly to human eyes) when you draw the first blue circle. Then, when you perform the avoid, targetting the exact blue with a tolerance of zero, nothing is shown because that true blue is not in the image.

    A tolerance of 255 works because that allows the avoid to match the “almost blue” color, and the result will be a circle that is “almost red.” If using a tolerance that high is unsettling, try very low tolerances(starting from 1 and going up) until you find one that is small but still matches the “almost blue” that you want to replace.

    The ideal solution would be to read the color value of the blue circle after drawing it, and target that exact color. This would be possible if you had the bitmap of the canvas you are working with, and you could call bitmap.getPixel(). However, I don’t know of any way to get a canvas’s bitmap if you don’t already have it(which you don’t in the onDraw method).

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

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This should work, since we're not using the g modifier,… May 16, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer Yes, this is microoptimization. Performance will be dominated by other… May 16, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer You could use output = `heroku create` See: http://ruby-doc.org/core/classes/Kernel.html May 16, 2026 at 11:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have made something like the following code: protected void Page_Load(object sender, EventArgs e)
I have a problem that has been bugging me all day. In my code
I have following code: public class readSensorsData extends Activity implements SensorListener { /** Called
I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
I have the following problem. My main activity consists of a ListView populated with
I use the following MSDN code on my master page to detect if the
I have the following in my Activity that I use to download a users
I have a problem with a site I am redesigning and the problem is
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
I use the following code to hide and show a box on a bunch

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.