用http.Client 从网络上读到图像文件,response body 是 io.Reader,可以直接输给 image.Decode
简单示例如下:
1 2 3 4 5 6 7 8 9
res, err = http.Get("URL HERE")
if err != nil || res.StatusCode != 200 {
// handle errors
}
defer res.Body.Close()
m, _, err := image.Decode(res.Body)
if err != nil {
// handle error
}
官方示例:
本文网址: https://golangnote.com/topic/237.html 转摘请注明来源