我有以下功能:func (rc ResizeController) Resize(c *gin.Context) { height := c.Query("height") width := c.Query("width") filepath := c.Query("file") h, err := strconv.ParseUint(height, 10, 32) w, err := strconv.ParseUint(width, 10, 32) file, err := os.Open("./test_images/" + filepath) if err != nil { log.Fatal(err) } image, err := jpeg.Decode(file) if err != nil { log.Fatal(err) } m := resize.Resize(1000, 100, image, resize.Lanczos3) buf := new(bytes.Buffer) jpeg.Encode(buf, m, nil) response := buf.Bytes() c.Data(200, "image/jpeg", response)}但我收到以下错误:controllers/resize_controller.go:41: cannot use h (type uint64) as type uint in argument to resize.Resizecontrollers/resize_controller.go:41: cannot use w (type uint64) as type uint in argument to resize.Resize我已经尝试了 strconv lib 中的一些不同功能,但没有成功!
1 回答
白板的微信
TA贡献1883条经验 获得超3个赞
无需使用任何strconv功能;只需将类型转换为uint:
h64, err := strconv.ParseUint(height, 10, 32)
if err != nil {
// TODO: handle error
}
w64, err := strconv.ParseUint(width, 10, 32)
if err != nil {
// TODO: handle error
}
h := uint(h64)
w := uint(w64)
- 1 回答
- 0 关注
- 291 浏览
添加回答
举报
0/150
提交
取消