转换并显示字节数组中的图像

转换并显示字节数组中的图像,第1张

转换并显示字节数组中的图像
  • 当您在Word文档中使用斜体时,图片就像..

我想我终于明白了这个项目符号的意思.. ;-)

投机的答案,但这里去:

如果您编写的图像看起来“歪斜”,则可能是由于BMP格式指定的每一列缺少填充(或BMP标头中的宽度字段不正确)。然后,我假设您获得EOF例外的图像的宽度不是4的倍数。

尝试使用ImageIO编写BMP,以查看是否有帮助:

private static BufferedImage createRGBImage(byte[] bytes, int width, int height) {    DataBufferByte buffer = new DataBufferByte(bytes, bytes.length);    ColorModel cm = new ComponentColorModel(ColorSpace.getInstance(ColorSpace.CS_sRGB), new int[]{8, 8, 8}, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);    return new BufferedImage(cm, Raster.createInterleavedRaster(buffer, width, height, width * 3, 3, new int[]{0, 1, 2}, null), false, null);}

byte[] bytes = ...; // Your image bytesOutputStream stream = ...; // Your outputBufferedImage image = createRGBImage(bytes, width, height);try {    ImageIO.write(image, "BMP", stream);}finally {    stream.close();}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5490686.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-12
下一篇2022-12-12

发表评论

登录后才能评论

评论列表(0条)

    保存