inputstream图片流转base64
时间: 2023-12-19 09:32:26 浏览: 62
图片转base64
4星 · 用户满意度95%
```java
import java.io.*;
import java.util.Base64;
public class ImageToBase64 {
public static String convertImageToBase64(InputStream inputStream) throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
byte[] imageBytes = outputStream.toByteArray();
return Base64.getEncoder().encodeToString(imageBytes);
}
}
```
阅读全文