您的位置:首页 > 理论基础 > 计算机网络

无损获取网络图片并转换成base64编码

2017-05-24 15:32 381 查看
public String changeImageBase64(String imgUrl){

URL url = null;
BufferedImage image = null;    
try{

url = new URL(imgUrl);         

image = ImageIO.read(url); 

String[] imgType = ImageIO.getReaderMIMETypes();

ByteArrayOutputStream baos = new ByteArrayOutputStream();  

ImageIO.write(image, "png", baos);

byte[] bytes = baos.toByteArray(); 
return Base64.encodeBase64(bytes)
 
}catch (Exception e) {  
e.printStackTrace();  
 

}  阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: