inputstream转bufferedimage
时间: 2024-02-05 12:04:46
浏览: 194
将InputStream转换为BufferedImage的步骤如下:
1. 使用ImageIO类的静态方法read()读取InputStream,返回一个BufferedImage对象。
2. 如果需要对图片进行处理,可以使用Graphics2D类的drawImage()方法将BufferedImage对象绘制到一个新的BufferedImage对象上。
3. 处理完成后,可以使用ImageIO类的静态方法write()将BufferedImage对象写入到输出流中。
示例代码如下:
InputStream inputStream = ...; // 获取输入流
BufferedImage bufferedImage = ImageIO.read(inputStream); // 将输入流转换为BufferedImage对象
// 对图片进行处理
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpg", outputStream); // 将BufferedImage对象写入输出流中
byte[] bytes = outputStream.toByteArray(); // 将输出流转换为byte数组
相关问题
bufferedimage转inputstream
将BufferedImage转换为InputStream的方法如下:
1.使用ByteArrayOutputStream将BufferedImage转换为字节数组。
2.使用ByteArrayInputStrea
multipartfile转bufferedimage
最低
0.47元/天
开通会员,查看完整答案
![left](https://csdnimg.cn/release/wenkucmsfe/public/img/header-left.7039297d.png)
成为会员后, 你将解锁
![right](https://csdnimg.cn/release/wenkucmsfe/public/img/header-right.4a55a819.png)
![benefits](https://csdnimg.cn/release/wenkucmsfe/public/img/icon-millions.57df8454.png)
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)