Is there any JavaFX Image editor?
Asked Answered
D

1

4

I want to put a simple raster graphics editor into my JavaFX app.
It seems that it can't be done using javafx.scene.image.Image because the graphics object is read-only.
Can somebody point me how can I do this or maybe there are some classes that provide direct access to pixel map?

upd: it is not necessary for editor to respond quickly, so the suggestions a-la create hidden java.awt.Canvas, handle all the events on ImageView to draw on the canvas, create by some means an output stream from the canvas to create new javafx Image and put it to ImageView.

Deemster answered 25/4, 2013 at 8:8 Comment(0)
H
13

You can use a JavaFX canvas to do this as shown in the Canvas Tutorial "Interacting with the User" section. You don't need a java.awt.Canvas.

You can take a snapshot of a canvas (or any other node) to create an image.

You can read a pixel map from an existing image using a PixelReader and write to an image's pixel map using a PixelWriter obtained from a WritableImage as shown in the ImageOps tutorials.

To write your resultant image to disk, convert it to a BufferedImage and write it out using ImageIO.

If you need it, there are samples of scaling images to a pixelated form (similar to the zoom function in Microsoft Paint): JavaFX ImageView without any smoothing.

Heiney answered 25/4, 2013 at 9:25 Comment(2)
Is it possible to disable image smoothing directly on a Canvas? I'm working on a similar project and would like to avoid a hidden Canvas if possible. Canvas.setScaleX() and its variants all create anti-aliased images, where I need to display a crisp image for a sprite editor.Hicks
I think not sorbet. I think the only way to do it is to read the pixels from the canvas, and write your own scaling logic, similar to JavaFX ImageView without any smoothing. Your question is slightly different from the original question. I encourage you to create a new question (link back to this question and the image smoothing question to help answerers understand the issues).Heiney

© 2022 - 2024 — McMap. All rights reserved.