42
A
回答
65
BufferedImage img = ImageIO.read(new ByteArrayInputStream(bytes));
1
根据Java文档,它看起来像你需要使用the MemoryImageSource Class把你的字节数组到内存中的对象,然后使用Component.createImage(ImageProducer的)下一个(通过在MemoryImageSource ,它实现ImageProducer)。
1
因为它听起来就像你已经知道的byte []数组中(如RGB,ARGB,BGR等)什么格式,你也许能够使用BufferedImage.setRGB(...),或BufferedImage.getRaster()和WritableRaster.setPixels(...)或WritableRaster.setSamples(...)的组合。不幸的是,这两种方法都需要根据图像格式将byte []转换为int [],float []或double []之一。
20
如果您知道图像的类型并且只想生成一个文件,则不需要获取BufferedImage实例。只需将字节写入具有正确扩展名的文件即可。
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(path));
out.write(bytes);
} finally {
if (out != null) out.close();
}
2
From Database.
Blob blob = resultSet.getBlob("pictureBlob");
byte [] data = blob.getBytes(1, (int) blob.length());
BufferedImage img = null;
try {
img = ImageIO.read(new ByteArrayInputStream(data));
} catch (IOException e) {
e.printStackTrace();
}
drawPicture(img); // void drawPicture(Image img);
相关问题
- 1. 对象数组到字节数组
- 2. 字节数组图像到位图
- 3. 字节数组到位图图像
- 4. 字节数组中LINQ到对象
- 5. 字节数组到图像转换
- 6. 字节数组到WriteableBitmap图像IValueConverter WP7
- 7. Silverlight 4,图像到字节数组
- 8. .NET核心字节数组到图像
- 9. JavaFx图像到字节[]数组(闭合)
- 10. 正从字节数组图像中JSON对象Android应用
- 11. 将PHP图像对象转换为AMFPHP的字节数组
- 12. 图像的字节数组
- 13. 对象数组的字节数组
- 14. 角色对象数组字节数组
- 15. ushort数组到图像对象
- 16. 从图像的字节数组调整图像的对比度
- 17. 转换字节数组图像并返回到字节数组,值改变
- 18. 对象数组到字节数组 - Marshal.AllocHGlobal碎片查询
- 19. 图像到字节数组到字符串(反之亦然)
- 20. 将对象转换为字节数组
- 21. Gdiplus ::来自字节数组的图像
- 22. 重建字节数组图像
- 23. 将图像转换为字节数组?
- 24. 字节数组在J2ME中的图像?
- 25. 的SqlDataSource - UpdateParameters与图像字节数组
- 26. GSP,从数组字节图像
- 27. 动态显示图像(字节数组)
- 28. SQL图像 - >字节数组
- 29. 将字节数组转换为图像
- 30. 字节数组输出为图像
这不回答这个问题,问题是用于写入图像文件。这个答案适用于读取图像文件。什么与所有的最高票? – Sixtoo 2015-12-25 15:50:33
标题说,但问题是他们有一个字节数组,需要一个图像,这就是它的作用。 – 2016-01-29 18:49:03