Go 阅读围棋中的图像

Go 阅读围棋中的图像,go,Go,我正在创造一个形象。我想读取现有图像并在此函数中返回。我该怎么做呢?类似这样的事情: 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 gree

我正在创造一个形象。我想读取现有图像并在此函数中返回。我该怎么做呢?

类似这样的事情:

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 (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
    }
    defer f.Close()
    image, _, err := image.Decode(f)
    return image, err
}
参考资料

试试这个:

func getImageFromFilePath(filePath string) (image.Image, error) {
    f, err := os.Open(filePath)
    if err != nil {
        return nil, err
    }
    defer f.Close()
    image, _, err := image.Decode(f)
    return image, err
}
参考资料


从何处?从目录中的图像读取现有图像从何处?从目录中的图像读取现有图像不要忘记导入图像、图像/png和图像/jpeg。这样:导入image\uimage/jpeg\uimage/png不要忘记导入image、image/png和image/jpeg。这种方式:导入图像u图像/jpeg u图像/png