我试图调整图像的尺寸,但在编译时得到一个常量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)
Run Code Online (Sandbox Code Playgroud)
我是Golang的新手但是这里的代码给了我错误
height := int(heightImg * a)
width := int(widthImg * a)
Run Code Online (Sandbox Code Playgroud)
任何建议都会很棒
Jim*_*imB 14
如果要乘以浮点数,则需要将数字转换为浮点数:
height := int(float64(heightImg) * a)
width := int(float64(widthImg) * a)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9442 次 |
| 最近记录: |