最近想再搞一下图像处理相关的东西,老是找不到好用的UI库,最后找到了这个,找了两个小时
gopackage main
import (
"image"
"log"
"os"
"gioui.org/app"
"gioui.org/op"
"gioui.org/op/paint"
"gioui.org/unit"
)
func main() {
go func() {
file, err := os.Open("./min.jpg")
if err != nil {
log.Fatal(err)
}
img, _, err := image.Decode(file)
if err != nil {
log.Fatal(err)
}
bounds := img.Bounds()
width := float32(bounds.Dx())
height := float32(bounds.Dy())
window := new(app.Window)
window.Option(app.Title("Image Viewer"))
window.Option(app.Size(unit.Dp(height), unit.Dp(width)))
err = run(window, img)
if err != nil {
log.Fatal(err)
}
os.Exit(0)
}()
app.Main()
}
func run(window *app.Window, img image.Image) error {
// theme := material.NewTheme()
var ops op.Ops
for {
switch e := window.Event().(type) {
case app.DestroyEvent:
return e.Err
case app.FrameEvent:
// This graphics context is used for managing the rendering state.
gtx := app.NewContext(&ops, e)
imageOp := paint.NewImageOp(img)
imageOp.Add(gtx.Ops)
paint.PaintOp{}.Add(gtx.Ops)
// Define an large label with an appropriate text:
//title := material.H1(theme, "Hello, Gio")
// Change the color of the label.
// Pass the drawing operations to the GPU.
e.Frame(gtx.Ops)
}
}
}
但也确实好看
就是反应有点慢
本文作者:yowayimono
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!