我正嘗試使用以下代碼將字符串轉換爲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