gpt4 book ai didi

java - 如何从 BufferedImage 中获取 InputStream?

转载 作者:IT老高 更新时间:2023-10-28 20:42:06 26 4
gpt4 key购买 nike

如何从 BufferedImage 对象中获取 InputStream?我试过了,但 ImageIO.createImageInputStream() 总是返回 NULL

BufferedImage bigImage = GraphicsUtilities.createThumbnail(ImageIO.read(file), 300);
ImageInputStream bigInputStream = ImageIO.createImageInputStream(bigImage);

图像缩略图正在正确生成,因为我可以成功地将 bigImage 绘制到 JPanel

最佳答案

来自 http://usna86-techbits.blogspot.com/2010/01/inputstream-from-url-bufferedimage.html

效果很好!

Here is how you can make an InputStream for a BufferedImage:

URL url = new URL("http://www.google.com/intl/en_ALL/images/logo.gif");
BufferedImage image = ImageIO.read(url);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(image, "gif", os);
InputStream is = new ByteArrayInputStream(os.toByteArray());

关于java - 如何从 BufferedImage 中获取 InputStream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/649186/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com