AvoidXferMode公差 [英] AvoidXferMode Tolerance

查看:368
本文介绍了AvoidXferMode公差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code的一个问题:

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);
}

据AvoidXfermode的API文档的公差值0意味着它寻找一个精确的色彩搭配。这应该在这里工作,因为我指定同一颜色为我所用绘制一个圆。但结果是,红色圆圈不绘制的。当我使用255的公差值,而不是那么它的工作原理(红色圆圈绘制它与蓝色碰撞),但听起来错的,因为这样的高耐受性,我认为它应该画出圆圈无处不在。

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.

那么,这里是错的? API文档? Android的?我?

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

推荐答案

是你的画布位深度RGB_565或ARGB_8888?我测试的这两种格式。它的工作在32位画布上,但16位的画布上,没有工作。 16位图像可能无法显示您正在绘制(0xFF0000FF)确切的颜色,因此它得到改变是如此微微(并潜移默化地对人眼)当你画的第一个蓝色圆圈。然后,当你执行避免,目标定位为零公差准确的蓝色,没有什么显示,因为,真正的蓝不是形象。

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.

255工程的宽容,因为这允许避免匹配几乎蓝色,其结果将是一个循环,几乎红。如果使用公差高的令人不安,尝试非常低公差(从1开始,往上走),直到你找到一个虽小但仍然匹配几乎蓝您要更换。

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.

理想的解决方案将是绘制后读的蓝色圆圈的颜色值和目标,准确的颜色。这将是可能的,如果你有你正在使用的画布的位图,你可以调用 bitmap.getPixel()。但是,我不知道有什么办法让一个帆布的位图,如果你不已经拥有了它(你在的onDraw方法不)。

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).

这篇关于AvoidXferMode公差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆