首先,我问这个具体的问题,因为我已经阅读了很多关于这个主题的例子,但是没有一个真正有用 .
我的问题是我想转换并显示jpg图像 . 我没有原始图像,它在服务器上 . 数据通过流(套接字)传递,并以字节数组形式给出 . 在该字节数组中,每4个字节代表一个像素的信息 . 我设法获得RGB并将它们转换/保存为bmp图像,但是我找不到一个可行的解决方案来制作jpg .
另一方面,我有一个BMP :)我怎么能在JLabel或JPanel中显示它?我也读过你的imageicon ImageIO等,但它对我不起作用 . 我使用ScheduleExecutorSystem btw . 也许这就是问题?
这是编码器代码(版权所有(C)2013 Philipp C. Heckel):
public static void encodeToBitmap(byte[] srcBytes, OutputStream destStream)
throws IOException {
int imageWidth = 1024;
int imageHeight = 1080;
int imageBytes = imageWidth * imageHeight * 3;
int filesizeBytes = imageBytes + BMP_SIZE_HEADER;
byte[] header = BMP_HEADER.clone(); // Clone bitmap header template, and
// overwrite with fields
header = writeIntLE(header, BMP_OFFSET_FILESIZE_BYTES, filesi