3
我想调整图像的大小,但得到一个常量0.8截断为整数编译错误。这是我的代码Golang我怎么能乘以一个整数和一个浮点数
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)
如果你想乘花车任何建议将是巨大
您可能会发现阅读“常量”是如何表达的有用信息。具体来说,在这种情况下,因为您的原始代码将整数“a”相乘,常数将转换为“int”,以便兼容。 https://blog.golang.org/constants – RayfenWindspear
感谢您的链接将读取,现在 –