Mad
Mad

Reputation: 11

Java2D help to show filling something to image

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.

Upvotes: 1

Views: 116

Answers (2)

trashgod
trashgod

Reputation: 205885

Conveniently, many classes implement the Shape interface. Implementing classes work well with fill(), as shown here. To display color transitions, consider AlphaComposite, shown here.

Upvotes: 2

Chris Dennett
Chris Dennett

Reputation: 22741

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.

Upvotes: 1

Related Questions