我正尝试使用以下代码将字符串转换为32位ubuntu上的uint。但它总是在uint64中转换它,尽管在函数中明确地传递了32作为参数。代码mw中的下面是image magick库的对象。当调用mw.getImageWidth()
和mw.getImageHeight()
时,返回uint
。此外,它接受resize函数中的uint
类型参数。将字符串转换为uint in lang
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)
}
}
错误是:
# 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
是什么UINT之间的区别,以及UINT32或uint和UINT64? – Naresh
'uint32'为32位,'uint64'为64位,'uint'为实现定义,32位或64位。请参阅[The Go Programming Language Specification:Numeric types](https://golang.org/ref/spec#Numeric_types)。 – peterSO
变量需要是u32,错误...不是u64 =) – bsbak