How to make colormap effect in javafx? -


i'd apply effect 8-bit image, associate each 8-bit input colour output 32-bit colour. applying effects replaces input colours associated.

i implement rewriting image bitmap programmatically. i'm afraid hamper efficiency. best implement such functionality effect.

how done?

one possibility (if understand correctly you're looking for) use writableimage indexed pixel format.

here example of simple animation updates index value changes, , sets pixels of image each time. seems pretty efficient, though there may more efficient ways achieve you're trying do.

import javafx.animation.animation; import javafx.animation.keyframe; import javafx.animation.keyvalue; import javafx.animation.timeline; import javafx.application.application; import javafx.beans.property.doubleproperty; import javafx.beans.property.simpledoubleproperty; import javafx.scene.scene; import javafx.scene.image.imageview; import javafx.scene.image.pixelformat; import javafx.scene.image.writableimage; import javafx.scene.layout.stackpane; import javafx.scene.paint.color; import javafx.stage.stage; import javafx.util.duration;  public class indexedimage extends application {      @override     public void start(stage primarystage) {         int width = 600 ;         int height = 600 ;         writableimage img = new writableimage(width, height);         byte[] pixels = createpixels(width, height);          doubleproperty hue = new simpledoubleproperty();         hue.addlistener((obs, oldvalue, newvalue) -> {             updateimage(img, pixels, newvalue.doublevalue());         });          timeline timeline = new timeline(new keyframe(duration.seconds(3), new keyvalue(hue, 360)));         timeline.setcyclecount(animation.indefinite);           scene scene = new scene(new stackpane(new imageview(img)));         primarystage.setscene(scene);         primarystage.show();          timeline.play();     }      private void updateimage(writableimage img, byte[] pixels, double hue) {         int[] colorindex = new int[256];         (int = 0 ; < colorindex.length; i++) {             color c = color.hsb(hue, 1.0*i/colorindex.length, 1.0);             colorindex[i] = getargb(c);         }         int w = (int) img.getwidth();         int h = (int) img.getheight();         img.getpixelwriter().setpixels(0, 0, w, h, pixelformat.createbyteindexedinstance(colorindex), pixels, 0, w);     }      private int getargb(color c) {         int = (int) (255*c.getopacity());         int r = (int) (255*c.getred());         int g = (int) (255*c.getgreen());         int b = (int) (255*c.getblue());         return (a << 24) | (r << 16) | (g << 8) | b ;     }      private byte[] createpixels(int width, int height) {         byte[] pixels = new byte[width * height];         int d = width * width + height * height;         (int = 0 ; < pixels.length; i++) {             int x = % width ;             int y = / width ;             pixels[i] = (byte) (256 * (height * y + width * x) / d);         }         return pixels ;     }      public static void main(string[] args) {         launch(args);     } } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -