问题描述
我拼命尝试从具有整数值的像素数组创建一个Image.不管使用WritableImage还是Canvas,总是说PixelFormat是BYTE_RGB或BYTE_BGRA_PRE,所以我不得不使用字节数组.
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.
是否可以将PixelFormat更改为<IntBuffer>
,或者我是否忽略了另一个具有PixelFormat<IntBuffer>
功能的组件?
Is there any way to change the PixelFormat to <IntBuffer>
or did I overlook another component that is capable of having a PixelFormat<IntBuffer>
?
推荐答案
您尚未在int[]
中描述像素数据的结构,但可以按照以下步骤进行操作:
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);
这篇关于从int数组创建Javafx图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!