问题描述
我试图替换颜色的东西,使用的。
从Android文档,它看起来像它正是我需要的:
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将无处不在画SRC除了在opColor的顶部,或者根据不同的模式,只绘制在opColor之上。
我想要是这样的:
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?
推荐答案
我终于找到了什么问题,也有一些线索在这里:的但它真的打我,当我看到这篇文章按埃里克·伯克。公差是失败,因为视图的画布是不是在8888模式。
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 by Eric Burke. The tolerance is failing because the view canvas is not in 8888 mode.
这意味着,当你画一个颜色或位图画布上的颜色被转换为目标像素格式和颜色可能会略有变化。为了解决这个问题您可以切换整个窗口像素格式为Eric的帖子看到,或者你可以画到8888后缓冲区。
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.
不幸的链接Eric的职位是死了,但罗马盖伊也有类似的写在这里:的
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/
这篇关于AvoidXferMode更换画布上的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!