用于图像序列化的SwingFXUtils替代品(Javafx,Swing,Raspberry Pi) [英] SwingFXUtils alternative for Image serialization (Javafx, Swing, Raspberry Pi)

查看:638
本文介绍了用于图像序列化的SwingFXUtils替代品(Javafx,Swing,Raspberry Pi)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的JavaFX应用程序的一种使用情况是在一侧加载图像,在TCP套接字上对其进行序列化,以在另一侧将其显示为JavaFX图像.

One of the use cases of my JavaFX application is to load an image on one side, serialize it over a TCP socket to show it as JavaFX image on the other side.

要实现此目的,我正在使用SwingFXUtils.fromFXImage()SwingFXUtils.toFXImage()创建并读取可以序列化的BufferedImage.

To implement this I am using SwingFXUtils.fromFXImage() and SwingFXUtils.toFXImage() to create and read a BufferedImage which can be serialized.

一切正常.但是我想在树莓派上运行显示侧.我发现,ARM上的JavaFX中没有Swing组件的集成,因此在Raspi上使用SwingFXUtils时得到NoClassDefFoundError.

Everything is working. But I would like to run the displaying side on a raspberry pi. As I found out, there is no integration of Swing components in JavaFX on ARM, so I get a NoClassDefFoundError when using SwingFXUtils on a Raspi.

请建议我如何在不使用SwingFXUtils的情况下创建和读取可序列化的图像对象?

Please suggest how I can create and read a serializable image object without the use of SwingFXUtils?

推荐答案

感谢您的回答.

@haraldK当然,在序列化之前,我已经将我的BufferedImage写入了ByteArray中.我昨晚的解释不够准确. Mea culpa.

@haraldK of course i have written my BufferedImage to a ByteArray before serialization. My explanation last night wasn't exact enough. Mea culpa.

我找到了解决我的问题的方法:为了使其在Raspberry Pi上工作,我只用InputStream替换了BufferedImage来读取包含图像数据的ByteArray.这使我可以使用InputStream创建JavaFX Image对象,而不是使用SwingFXUtils.

I found a solution for my problem: To make it work on a Raspberry Pi I just substituted BufferedImage with an InputStream to read my ByteArray containing the image data. This allowed me to create the JavaFX Image object with an InputStream instead of using SwingFXUtils.

之前:

BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageUpdate.getImageByteArray()));

imageView.setImage(SwingFXUtils.toFXImage(bufferedImage, null));

,其中imageUpdateImageUpdate对象,用于通过TCP套接字传输数据(包含图像和其他数据).

, where imageUpdate is an ImageUpdate Object used for data transport over TCP sockets (containing image and additional data).

如前所述,这会产生

Exception in thread "..." java.lang.NoClassDefFoundError: javafx/embed/swing/JFXPanel

在Raspberry Pi上,因为缺少用于ARM体系结构的JavaFX Port中的Swing类.

on the Raspberry Pi because of missing Swing Classes in JavaFX Port for ARM architecture.

之后:

InputStream inputStream = new ByteArrayInputStream(imageUpdate.getImageByteArray());

imageView.setImage(new Image(inputStream));

此解决方案现在可以像在我的Raspberry Pi上一样使用.

This solution works now like a charm on my Raspberry Pi.

这篇关于用于图像序列化的SwingFXUtils替代品(Javafx,Swing,Raspberry Pi)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆