Java2D 帮助显示填充图像的内容
我正在做一个实施虚拟化学实验室系统的项目。我尝试使用 java2D 来做到这一点。我在这里遇到了一个大问题。这就是如何向烧杯或烧瓶显示某种填充效果(烧杯是图像)。我使用 WritableRaster(java.awt.image) 类中的 setPixel() 方法尝试了这一点。但并没有多大用处。
我需要帮助来显示烧杯中的填充物以及混合两种化学品时的颜色变化。请记住,烧杯是一个图像。如果有人能给我一个包含示例代码的解决方案,请提前致谢。
I'm doing a project to implement virtual chemistry laboratory system. I tried to do this by using java2D. I have come across a big issue here. that is how to show some kind of filling effect to a beaker or to a flask (beaker is an image). I tried out this with setPixel() method in WritableRaster(java.awt.image) class. but it is not much useful.
I need a help to show something filling to a beaker and to show color change when mixing two chemicals. please remember that beaker is an image. thanks in advance if anyone can give me a solution with sample code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了方便起见,许多类都实现了
Shape
接口。使用fill()
可以很好地实现类,如图 在这里。要显示颜色过渡,请考虑使用AlphaComposite
,如此处所示。Conveniently, many classes implement the
Shape
interface. Implementing classes work well withfill()
, as shown here. To display color transitions, considerAlphaComposite
, shown here.我建议使用动态 SVG 画布 Batik,然后你可以使用先进的高级功能,如蒙版和混合等。这不是最有效的解决方案,但谁在乎呢?它对未来很灵活。此外,还需要进行大量优化才能找出图像的哪些部分实际上发生了变化,并将其传递以提高效率。我希望蜡染布能够将其作为标准。另外,你还会得到一些看起来非常漂亮的东西。
不管怎样,你只需要使用 Inkscape 创建 SVG,然后相应地修改 DOM(文档对象模型)即可。这就像搞乱 HTML 一样。 这里是一些 SVG 烧杯剪贴画。
I'd advise using a dynamic SVG canvas using Batik, and then you can use advanced high-level features like masks and blending and such. It's not the most efficient solution, but who cares? It's flexible for the future. Also, it'd take a lot of optimisation to work out what parts of the image have actually changed and pass that through for efficiency. I expect Batik does that as standard. Also, you'll have something that looks really very nice.
Anyway, then you just need to use Inkscape to create the SVG, and then modify the DOM (Document Object Model) accordingly. It's just like messing with HTML. Here is some SVG beaker clipart.