2

I am desperately trying to create an Image from a pixel-array with integer values. Regardless of using the WritableImage or the Canvas, it is always said that the PixelFormat is BYTE_RGB or BYTE_BGRA_PRE, so that I am forced to use a byte-array.

Is there any way to change the PixelFormat to <IntBuffer> or did I overlook another component that is capable of having a PixelFormat<IntBuffer>?

1 Answer 1

6

You haven't described the structure of the pixel data in your int[], but you can do something along the lines of

int[] pixels = ... ;
WritableImage img = new WritableImage(width, height);
PixelWriter pw = img.getPixelWriter();
pw.setPixels(0, 0, width, height, PixelFormat.getIntArgbInstance(), pixels, 0, width);
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much four answer! Using PixelWriters setPixels()-method seem not work for me properly. The image doesn't appear! My ImageView only loads it when changing to byte[] pixelarray and byte-PixelFormat it shows up.Also System.out.println(img.getPixelWriter().getPixelFormat().getType()); spids out „BYTE_BGRA_PRE“
What is actually in your array of ints?
Well... what are you actually expecting to see then? If all the pixels have zero alpha, they are all transparent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.