我将 golang 中的图像加载到 image.Image 格式,但出现此错误:"image: unknown format"这是我的功能:import "image"url := "https://i.imgur.com/m1UIjW1.jpg"func loadImageFromURL(URL string) (image.Image, error) { //Get the response bytes from the url response, err := http.Get(URL) if err != nil { return nil, err } defer response.Body.Close() if response.StatusCode != 200 { return nil, errors.New("received non 200 response code") } img, _, err := image.Decode(response.Body) if err != nil { return nil, err } return img, nil}缺少的是这个导入:import _ "image/jpeg"
1 回答
- 1 回答
- 0 关注
- 249 浏览
添加回答
举报
0/150
提交
取消