Search code examples
imagejavafxpixel

JavaFx Displaying Images from pixel array


I changed pixel array of an image, and I want to display it. I tried this code (below), but it's doesn't work.

int[] pixelSrcImage;
PixelGrabber pgSrc = 
new PixelGrabber(imageSrc, 0, 0, imageHeight, imageWidth, pixelSrcImage, 0,imageWidth);
pgSrc.grabPixels();

pixelSrcImage[...]=...

PixelWriter pw = null;
WritablePixelFormat<IntBuffer> format = WritablePixelFormat.getIntArgbInstance();
pw.setPixels(0, 0, imageWidth, imageHeight,   format, step, 0, imageWidth);
Image imView = new Image (pw.???);

Solution

  • You need to define the destination image first and not set the PixelWriter to null.

    WritableImage image = new WritableImage(width, height);
    PixelWriter pw = image.getPixelWriter();
    

    All I can see from your bits & pieces is that you'll get a NullPointer Exception.

    And please consider what jewelsea said.