我是靠谱客的博主 顺利电源,这篇文章主要介绍浏览器显示图片,后端返回给页面/img标签图片,现在分享给大家,希望可以做个参考。

@RequestMapping(value = "/tupian", method = RequestMethod.GET)
public void IoReadImage(HttpServletRequest request, HttpServletResponse response, String imgPath) throws IOException {
ServletOutputStream out = null;
FileInputStream ips = null;
try {
//获取图片存放路径
//String imgPath = "D:\学习\linux文件\shiJuan-1-500\0ac201615a63409db498477004f34d9f.jpg";
ips = new FileInputStream(new File(imgPath));
response.setContentType("image/png");
out = response.getOutputStream();
//读取文件流
int len = 0;
byte[] buffer = new byte[1024 * 10];
while ((len = ips.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
out.close();
ips.close();
}
}

这个是根据图片地址返回给页面图片;直接url请求页面显示该图片

img标签显示该图片:


只设置了高
<img id="img1" src="自己的url" alt="" style="height: 750px"></body>

 

最后

以上就是顺利电源最近收集整理的关于浏览器显示图片,后端返回给页面/img标签图片的全部内容,更多相关浏览器显示图片内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部