doufulian4076
2016-02-02 13:30
浏览 2.4k
已采纳

在go lang中将字符串转换为uint

I am trying to convert the string to uint on 32-bit ubuntu using the following code. But it always convert it in uint64 despite explicitly passing 32 as the argument in the function. Below in the code mw is the object of the image magick library. Which returns uint when mw.getImageWidth() and mw.getImageHeight() is called. Also, it accepts the uint type argument in the resize function.

    width :=  strings.Split(imgResize, "x")[0]
    height := strings.Split(imgResize, "x")[1]

    var masterWidth uint = mw.GetImageWidth() 
    var masterHeight uint = mw.GetImageHeight() 

    mw := imagick.NewMagickWand()
    defer mw.Destroy()

    err = mw.ReadImageBlob(img)
    if err != nil {
            log.Fatal(err)
        } 

    var masterWidth uint = mw.GetImageWidth() 
    var masterHeight uint = mw.GetImageHeight()

    wd, _ := strconv.ParseUint(width, 10, 32)
    ht, _ := strconv.ParseUint(height, 10, 32)

   if masterWidth < wd || masterHeight < ht { 
     err = mw.ResizeImage(wd, ht, imagick.FILTER_BOX, 1)
     if err != nil {
        panic(err)
    } 
   }

Error is :

# command-line-arguments
test.go:94: invalid operation: masterWidth < wd (mismatched types uint and uint64)
goImageCode/test.go:94: invalid operation: masterHeight < ht (mismatched types uint and uint64)
goImageCode/test.go:100: cannot use wd (type uint64) as type uint in argument to mw.ResizeImage
goImageCode/AmazonAWS.go:100: cannot use ht (type uint64) as type uint in argument to mw.ResizeImage
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新