0

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!

  • Please amplify on your image processing goal(s): interactive? online? offline? – trashgod Mar 05 '22 at 00:07
  • @trashgod I updated the post to (I believe) explain what you're asking for – MythicalMoose Mar 05 '22 at 00:15
  • 1
    [Using the Image Ops API](https://docs.oracle.com/javafx/2/image_ops/jfxpub-image_ops.htm) or [maybe this](http://www.cse.uaa.alaska.edu/~afkjm/csce201/handouts/LoopsImages.pdf) or [Drawing user input on Image JavaFX](https://stackoverflow.com/questions/24681018/drawing-user-input-on-image-javafx) or [JavaFX Canvas Example](https://examples.javacodegeeks.com/desktop-java/javafx/javafx-canvas-example/) – MadProgrammer Mar 05 '22 at 00:57
  • 1
    For interactive use, edit like [this](https://stackoverflow.com/a/70827873/230513), take a `snapshot()` and save it to a file like [this](https://stackoverflow.com/q/48124777/230513). – trashgod Mar 05 '22 at 01:26
  • 1
    “It looks like JavaFX images can only be loaded from a file.” [No.](https://openjfx.io/javadoc/17/javafx.graphics/javafx/scene/image/WritableImage.html) – James_D Mar 05 '22 at 03:16
  • 1
    You can apply blends and color adjustments using effects to canvases and image views. You can localize these filters via clips and layers. You can snapshot the canvas or ImageView nodes that have the clipped effects applied to generate images. You can save those images via imageio. Because I don’t fully understand your problem, I am not saying you should do that for your situation, probably not in fact. Or you could create a custom algorithm and manipulate data in the image or canvas at a pixel or backing buffer level. Just providing info on related capabilities. – jewelsea Mar 05 '22 at 04:09

0 Answers0