本文整理匯總了Golang中github.com/nelsam/gxui.Driver.CreateTexture方法的典型用法代碼示例。如果您正苦於以下問題:Golang Driver.CreateTexture方法的具體用法?Golang Driver.CreateTexture怎麽用?Golang Driver.CreateTexture使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/nelsam/gxui.Driver
的用法示例。
在下文中一共展示了Driver.CreateTexture方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createIconButton
func createIconButton(driver gxui.Driver, theme gxui.Theme, iconPath string) gxui.Button {
button := theme.CreateButton()
button.SetType(gxui.PushButton)
fileBytes, err := assets.Asset(iconPath)
if err != nil {
log.Printf("Error: Failed to read asset %s: %s", iconPath, err)
return button
}
f := bytes.NewBuffer(fileBytes)
src, _, err := image.Decode(f)
if err != nil {
log.Printf("Error: Failed to decode image %s: %s", iconPath, err)
return button
}
src = resize.Resize(24, 24, src, resize.Bilinear)
rgba := image.NewRGBA(src.Bounds())
draw.Draw(rgba, src.Bounds(), src, image.ZP, draw.Src)
texture := driver.CreateTexture(rgba, 1)
icon := theme.CreateImage()
icon.SetTexture(texture)
button.AddChild(icon)
return button
}
示例2: appMain
func appMain(driver gxui.Driver) {
args := flag.Args()
if len(args) != 1 {
fmt.Print("usage: image_viewer image-path\n")
os.Exit(1)
}
file := args[0]
f, err := os.Open(file)
if err != nil {
fmt.Printf("Failed to open image '%s': %v\n", file, err)
os.Exit(1)
}
source, _, err := image.Decode(f)
if err != nil {
fmt.Printf("Failed to read image '%s': %v\n", file, err)
os.Exit(1)
}
theme := flags.CreateTheme(driver)
img := theme.CreateImage()
mx := source.Bounds().Max
window := theme.CreateWindow(mx.X, mx.Y, "Image viewer")
window.SetScale(flags.DefaultScaleFactor)
window.AddChild(img)
// Copy the image to a RGBA format before handing to a gxui.Texture
rgba := image.NewRGBA(source.Bounds())
draw.Draw(rgba, source.Bounds(), source, image.ZP, draw.Src)
texture := driver.CreateTexture(rgba, 1)
img.SetTexture(texture)
window.OnClose(driver.Terminate)
}