AvoidXferMode to replace a color on canvas

I'm trying to replace a color for something that is drawn on a Canvas using AvoidXferMode. From the android docs it looks like it's exactly what I need:

AvoidXfermode xfermode will draw the src everywhere except on top of the opColor or, depending on the Mode, draw only on top of the opColor.

What I'm trying is something like this:

Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawPaint(paint); // actually drawing a bitmap here
paint.setXferMode(new AvoidXferMode(Color.RED, 0, TARGET);
paint.setColor(Color.GREEN);
canvas.drawPaint(paint);

However, this just gives a red screen, not green as I would expect (replacing the red with green). I guess I'm missing the point some where...Any suggestions?

Answers


I finally found out what is issue is, there are some clues here: AvoidXferMode Tolerance but it really hit me when I read this post http://stuffthathappens.com/blog/2010/06/04/android-color-banding/ by Eric Burke. The tolerance is failing because the view canvas is not in 8888 mode.

That means that when you draw a color or bitmap on that canvas the colors get converted to the target pixel format and the color might slightly change. To fix this you can either switch the entire window pixel format as seen in Eric's post or you can draw onto a 8888 back buffer.

Unfortunately the link to Eric's post is dead, but Roman Guy also has a similar write up here: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/


Need Your Help

How should I set up complex Factories in Rails?

ruby-on-rails rspec factory-girl

In my rails application I have three objects I would like to model for a particular Rspec test. These are Organizations, Users, and Sales Opportunities.

pgAdmin server not showing up

pgadmin

Total n00b question here. I am using pgAdmin to attempt to administer a remote PostgreSQL server. I click the connect icon, fill out the form, click 'OK'. The form goes away and in the status bar it

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.