加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

我如何在golang中将uint64转换为uint?

发布时间:2020-12-16 09:28:37 所属栏目:大数据 来源:网络整理
导读:我有以下功能: 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,32) file,err :=
我有以下功能:

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,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.Resize
controllers/resize_controller.go:41: cannot use w (type uint64) as type uint in argument to resize.Resize

我从strconv lib尝试了一些不同的功能,没有运气!

提前致谢

解决方法

无需使用任何strconv函数;只做一个 type conversion到uint:

h64,32)
// TODO: check err
w64,32)
// TODO: check err
h := uint(h64)
w := uint(w64)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读