Go 非常新(我正在做的第一個簡單項目)。問題:如何從 URL 獲取圖像,然后將其保存到我的計算機?這是我到目前為止所擁有的:package mainimport ("fmt""net/http""image""io/ioutil")func main() { url := "http://i.imgur.com/m1UIjW1.jpg" // don't worry about errors response, _ := http.Get(url); defer response.Body.Close() m, _, err := image.Decode(response.Body) error := ioutil.WriteFile("/images/asdf.jpg", m, 0644)}但是,當我運行此代碼時,我得到 cannot use m (type image.Image) as type []byte in function argument我假設我必須將 image.Image (variable m) 轉換為未定義的字節(jié)數?這是解決這個問題的正確方法嗎?
- 3 回答
- 0 關注
- 235 瀏覽
添加回答
舉報
0/150
提交
取消