func (sticky *Sticky) DrawImage(W, H int) (img *image, err error) {
myImage := image.NewRGBA(image.Rect(0, 0, 10, 25))
myImage.Pix[0] = 55 // 1st pixel red
myImage.Pix[1] = 155 // 1st pixel green
return myImage ,nil
}
我正在创建图像。我想阅读现有的图像并返回此函数。我该怎么做?
最佳答案
像这样:
func getImageFromFilePath(filePath string) (image.Image, error) {
f, err := os.Open(filePath)
if err != nil {
return nil, err
}
image, _, err := image.Decode(f)
return image, err
}
引用关于go - 在Go中读取图像,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49594259/