在android上的触摸绘制上创建喷雾效果 - java

Improve this question

我的应用程序要求我在用户触摸屏幕时创建类似喷雾的效果。用户可以选择颜色。我需要使用用户选择的颜色创建类似喷雾的效果。我不确定是否可能。如果可能的话,请给我建议一个链接或指南。

参考方案

您只需要在画布上使用公共绘制部分即可...然后指定要绘制的半径。然后使用“随机”功能,在用户按下的时间内,在使用半径定义的圆的区域内绘制(x)个点。如果您需要更多确切的帮助,请告诉我。

[编辑]
这将是非常伪的代码。但是您应该可以很容易地使代码从中工作。

// This needs to happen in the down press on the canvas
if(currentBrush == Brush.SPRAY_CAN){
    int dotsToDrawAtATime = 20;
    double brushRadius = 1.0; // This is however large they set the brush size, could be (1), could be whatever the max size of your brush is, e.g., (50), but set it based on what they choose

    for (int i = 0; i < dotsToDrawAtATime; i++){
        // Pick a random color for single dot to draw
        // Get the circumference of the circle (2*pi*brushRadius), based on the X/Y that the user input when they pressed down. Pick a random spot inside that area, and draw a single dot. As this is a for loop, it will happen 20 different times for this one occurrence.
    }
}

[编辑2]
如果您要使用它,我将极力考虑合并Iain_b的方法。请考虑他的职位。

[编辑3]
这是一张图片...也许可以帮助您了解...

[编辑4]

这是我的代码,使用lain_b的添加部分进行了更新,以帮助简化它。

// This needs to happen in the down press on the canvas
if(currentBrush == Brush.SPRAY_CAN){
    int dotsToDrawAtATime = 20;
    double brushRadius = 1.0; // This is however large they set the brush size, could be (1), could be whatever the max size of your brush is, e.g., (50), but set it based on what they choose

    for (int i = 0; i < dotsToDrawAtATime; i++){
        // Pick a random color for single dot to draw
        ...

        // Get the location to draw to
        int x = touchedX + Random.nextGaussian()*brushRadius;
        int y = touchedY + Random.nextGaussian()*brushRadius;

        // Draw the point, using the random color, and the X/Y value
        ...
    }
}

绑定Java库Xamarin.Android - java

我花了两天时间在每个论坛,文档,tuto,博客等上寻找答案。我为实习生启动了一个Android应用程序,因为我不懂Java,所以用xamarin C#开发了它。直到最近一切都还不错,但现在我需要集成一个SDK才能在应用程序中使用POS(销售点),但是该库是用Java编写的,即使跟随文档或辅导老师,我也无法将其与xamarin绑定(我什至无法调试)。这里有人已…

Java:线程池如何将线程映射到可运行对象 - java

试图绕过Java并发问题,并且很难理解线程池,线程以及它们正在执行的可运行“任务”之间的关系。如果我创建一个有10个线程的线程池,那么我是否必须将相同的任务传递给池中的每个线程,或者池化的线程实际上只是与任务无关的“工人无人机”可用于执行任何任务?无论哪种方式,Executor / ExecutorService如何将正确的任务分配给正确的线程? 参考方案 …

JAVA:字节码和二进制有什么区别? - java

java字节代码(已编译的语言,也称为目标代码)与机器代码(当前计算机的本机代码)之间有什么区别?我读过一些书,他们将字节码称为二进制指令,但我不知道为什么。 参考方案 字节码是独立于平台的,在Windows中运行的编译器编译的字节码仍将在linux / unix / mac中运行。机器代码是特定于平台的,如果在Windows x86中编译,则它将仅在Win…

java:继承 - java

有哪些替代继承的方法? java大神给出的解决方案 有效的Java:偏重于继承而不是继承。 (这实际上也来自“四人帮”)。他提出的理由是,如果扩展类未明确设计为继承,则继承会引起很多不正常的副作用。例如,对super.someMethod()的任何调用都可以引导您通过未知代码的意外路径。取而代之的是,持有对本来应该扩展的类的引用,然后委托给它。这是与Eric…

Java:BigInteger,如何通过OutputStream编写它 - java

我想将BigInteger写入文件。做这个的最好方式是什么。当然,我想从输入流中读取(使用程序,而不是人工)。我必须使用ObjectOutputStream还是有更好的方法?目的是使用尽可能少的字节。谢谢马丁 参考方案 Java序列化(ObjectOutputStream / ObjectInputStream)是将对象序列化为八位字节序列的一种通用方法。但…