如何使用Go在Windows上显示图像?

Go程序在 Windows显示图像的最简单方法是什么?我有一个基于教程的片段:
package main

import (
    "image" 
    "image/color" 
    "image/draw" 
)

func main() {
    m := image.NewRGBA(image.Rect(0,640,480))
    blue := color.RGBA{0,255,255}
    draw.Draw(m,m.Bounds(),&image.Uniform{blue},image.ZP,draw.Src)
}

但是如何显示对象m?我想弹出一个窗口并在那里显示图像,而不是先将其写入文件.

gxui中有一个图像查看器示例,它显示从命令行frags中选择的图像.结果可以在 here看到.这可能是使用go来呈现这个gui的简单方法之一.

请注意gxui是经验性的,未来的更新可能会破坏您的代码.

对于您的请求,代码如下.它会生成一个显示图像的窗口,一个完整的蓝色图像.

package main

import (
    "image"
    "image/color"
    "image/draw"

    "github.com/google/gxui"
    "github.com/google/gxui/drivers/gl"
    "github.com/google/gxui/themes/dark"
)

func appMain(driver gxui.Driver) {
    width,height := 640,480
    m := image.NewRGBA(image.Rect(0,width,height))
    blue := color.RGBA{0,draw.Src)

    // The themes create the content. Currently only a dark theme is offered for GUI elements.
    theme := dark.CreateTheme(driver)
    img := theme.CreateImage()
    window := theme.CreateWindow(width,height,"Image viewer")
    texture := driver.CreateTexture(m,1.0)
    img.SetTexture(texture)
    window.AddChild(img)
    window.OnClose(driver.Terminate)
}

func main() {
    gl.StartDriver(appMain)
}

我确认这适用于Windows和Linux.它可能适用于MacOSX.

如果是用于生产,您可能需要查看更稳定的包.例如,ComputerFellow提到的go-qml或go-qt5

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...