Using vector graphics with JavaFX - java

All the images in my app are currently jpg or png, which used to be okay. The GUI was a fixed size appropriate for whatever screen it would be displayed on and everyone was happy.
Now that hi-res and retina displays are more common, the app at its normal size looks small on some screens (or fuzzy if resized), so I'd like to update the graphics to adapt to any future resolution advances by converting them to vector images (eps or svg).
Before I go do this, does JavaFX have a way to use vector images in a similar way to ImageViews? It looks like ImageView itself only supports JPG, PNG, BMP, and GIF.

No JavaFX does not support things like SVG directly but there are solutions like:
- SVG to FXML
- useage of a webview
BTW Image supports hi-res by using #2x notion eg you supply image.png and image#2x.png and JavaFX choose the right one depending on the screen resolution

Related

Are there any ways to modify a JavaFX Image Object?

I'm showing an Image on a Canvas using JavaFX, but I would like the color of certain parts of the image to vary based on a variable. Ordinarily, I imagine this would be accomplished by creating a color mask and adding that to the image, but as far as I can find JavaFX Image doesn't allow any operations like that, and from the documentation it looks like JavaFX Images can only be loaded from a file. I don't want to modify and then reload the file each time the color changes, because that seems pretty inefficient performance-wise.
My goal is to create an interactive offline app in which a small character is shown, and the user can (for example) use an input to change the characters eye/hair color.
Are there any ways to accomplish this? Essentially doing basic image masking/coloration with JavaFX Images and canvases. (Not ImageView)
Thanks for any advice you can give me!

How to draw outline around a PNG image using JAVA in Android Studio?

I have a PNG image (with transparent background) and I want to draw an outline around its visible pixels only. (See example GIF attached). I want to get this all done in JAVA.
I've read many Q&A over stackoverflow and around the web but I didn't find anything anyway near to my requirements.
P.S: We don't have to draw the same image twice on canvas and use the bottom one as outline, so please don't propose such solutions.
P.P.S: I would be great if this solution lets me draw an outline around all visible objects/elements (images & textviews etc) inside a canvas or inside a layout.
Try using Open CV and drawing contours. It is the closest available solution

Which image formats can be resized in JavaFX

There are about 100 jpeg & png color images used in our JavaFX-built desktop app which, when the window is resized, become stretched and blurry so I'd like to have all the graphics remade in a format that will allow them to be dynamically resized without losing quality. What image format or procedure should be used to do this?
Currently, each image is simply in an ImageView and resized as follows, but I'm open to other suggestions:
if(isSmall){
Rectangle2D visualBounds = Screen.getPrimary().getVisualBounds();
double sh = visualBounds.getHeight();
Scale scale = new Scale(sh, sh, 0, 0);
root.getTransforms().setAll(scale);
}
As has already been mentioned SVG is probably the way to go for you. JavaFX does not support SVG directly but you can find support here
javafxsvg and here svg-to-fxml-converter for example.
You can't resize an image to be bigger than it is without it getting blurry for most common formats. Instead make sure your images are big enough so you only need to downscale them.
The only format I ever heard of that could upscale further was using fractal compression, but AFAIK it is not in common use.

Java Drawing shapes to file of 2D object

I have a play framework application which I want to be able to produce a product label from. I have the label design in illustrator. It consists of a black circle, white writing with a QR code in the middle, also has curved text.
I want to create a high resolution PDF and/or image file of this design on the fly. All most all of the drawing stuff I find for java relates to swing.
Anyone done this?
The basic class which allows creating an image programatically is BufferedImage and the corresponding Graphics2D class. You are not forced to use it with Swing. You can easily convert it to common graphic formats like PNG. Then you can save it as an image file or place it in a generated(e.g. with iText) PDF.
http://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html
http://docs.oracle.com/javase/7/docs/api/java/awt/Graphics2D.html
In other words - yes, it can be done.
But if I ware you I would consider exporting the design from Illustrator to a file and use it as a resource in your application. But if you need to scale it programatically you ought to consider using SVG format to avoid loosing quality. Java does not have build-in support for vector images so you should look at
Apache Batik

GIF file creation library with full GIF support

There are many libraries for saving images in GIF format, but is there a library with support for GIFs more advanced (or archaic and forgotten if you will) features?
I am thinking about the plain text extension, as well as the ability to redraw only portions of the image for each new frame. The plain text extension could theoretically be used to complement image drawing as well and improve compression of animations, for instance.
I.e. (a)buse the plain text extension to render graphics instead of text. (Most languages would do.)
GIFLIB should have everything from GIF
Is this what you mean about plain text?
http://giflib.sourceforge.net/gif_lib.html#idp4823712
Here is the partial frame update
http://giflib.sourceforge.net/gif_lib.html#idp79616
For .NET (full disclosure, I work at Atalasoft) DotImage Photo Free can do the portion redraw. Look at GifFrame and GifFrameDisposal. You specify what to do with the previous frame when you draw the new one. Each frame can be any size and positioned, so you can draw only a portion of the image.

Categories

Resources