Java2D help to show filling something to image - java

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.

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

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.

Related

How to program a GIF using any type of image/ object with processing?

I have used Java language for beginners is used with object type calling so there's an app or software called processing that I used that's a bit easy at making programs... (https://processing.org/)
What could be the best shortest example to make a animated GIF using shapes/ images?
What way could be the best way to make a GIF animated in regular Java without using processing software?
What could be the easiest examples for a beginner to do an animated GIF?
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:
You need to break your problem down into smaller steps and then take those steps on one at a time. Can you create a simple animation? Something simple like a circle moving around the screen. Separately from that, can you export a single .png image from a sketch? Again, just something simple. Work your way forward in small steps: can you then export each frame of a simple animation as a .png file?
Then when you have those .png files, you can use something like Image Magick to convert them into an animated gif file.
The Processing reference is your best friend for questions like this. The save() and saveFrame() functions could come in handy for exporting an animation as a gif.
Please try something, and if you get stuck, post a MCVE along with a more specific technical question in a new post. Good luck.

How to draw efficiently arrows on a canvas with JavaFX 8?

I am looking for a very simple and efficient way to draw arrows in JavaFX 8, what is the best way to achieve that (performance-wise if let's say I'm willing to draw hundreds or thousands of them)?
I've heard using a Canvas to draw on it is quite efficient.
However, I do not know whether the best implementation is to go with:
Inheriting from the class Shape [https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Shape.html]
Inheriting from the class Line? [https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/Line.html]
Bothering myself every now and then with the GraphicContext class in order to create the arrow manually? Does not sound like the good idea.
Other strategy?
The best method depends on various factors which we don't know so it's difficult to give a clear answer here. I will try to give a few general hints though and you will have to decide yourself if these are applicable to your problem.
For mass drawings using the canvas sounds like a good idea.
Simple lines and rectangles are much faster than paths (also polylines and polygons).
Some line joins/caps are faster than others.
Avoid transparency.
It may be helpfull to consider specialized approaches like, e.g. creating images of your arrows and then just painting these images.
Michael

Convert image to sketch and then cartoonify?

My aim is to let the user take a selfie from my app and then apply different image processing algorithms to convert it in a cartoon type image. I followed the algo written here, and then also used the method written just below the chosen answer to convert black and white sketch to colored image that should look like cartoon. Every thing is ok except that after applying Gaussian Blur , the image becomes too hazy and unclear. Here is the image output:
Any advice how I can make it more clear? Like shown in this link. I know they used Photoshop , but I want to achieve it with Java and Android.
PS: I found all the image processing methods from here. Plus the method mentioned here (the one below the chosen answer), what could be the ideal values in the arguments?
cartoonifying image
If you have a basic knowledge of C++, you can port this app for your need.
This application works real time. If you want to non-real time,than you can use bilateral filter against two medianBlurs at the bottom of function. That will give better results, but bad performance. But you need to use OpenCV in your application. If you want to make application with more functions, I will suggest you to do it.

Detect text in an image (simple)

I built a simple OCR to detect text. I now need to identify and segment the text from the source image. I used the Canny edge detector to get something like this.
http://i.imgur.com/at4YTb2.png
Sorry, I don't have enough reputation to post images.
I can't figure out a way to separate the text part. I have read,
http://www.math.tau.ac.il/~turkel/imagepapers/text_detection.pdf which is using the Stroke Width Transform
ROBUST TEXT DETECTION IN NATURAL IMAGES WITH EDGE-ENHANCED MAXIMALLY STABLE EXTREMAL REGIONS
The algorithms described are probably the best answers but are very difficult to implement in Java. Moreover, in my use cases the text would be prominent much like above. The above algorithms seem like overkill. I would be grateful if anyone can suggest any alternative to solve this problem. Thanks!

Creating a percentage bar with Java and iText

I'm a developer on a larger web application in which I've implemented a system to create and answer questionnaires. To review the results, it looks like this:
Now I want to make a printable report with iText, which should look pretty much the same. But I have no clue how to make the percentagebars with iText.
If it's possible it should have the same greenish image background, and then a solid color showing the % on top of that.
Any help would be much appreciated :-)
Check out these examples:
http://itextpdf.com/book/chapter.php?id=10

Categories