我试图调整图像的尺寸,但是在编译时将常数0.8截断为整数错误。这是我的代码
b := img.Bounds()
heightImg := b.Max.Y // height of image in pixels
widthImg := b.Max.X // width of image in pixels
const a = .80
height := int(heightImg * a) // reduce height by 20%
width := int(widthImg * a) // reduce width by 20%
// resize image below which take in type int, int in the 2nd & 3rd parameter
new_img := imaging.Resize(img,width,height, imaging.Lanczos)
我是golang的新手,但是这里的代码给了我错误
height := int(heightImg * a)
width := int(widthImg * a)
任何建议都很好
如果要乘以浮点数,则需要将数字转换为浮点数:
height := int(float64(heightImg) * a)
width := int(float64(widthImg) * a)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句