Network Internet Images- Fyne GUI Golang tutorial 26

Want to fetch images from internet ? You can easily do it in Fyne.

This tutorial is focused on displaying assets from internet.

Just 2 lines of code to fetch image from internet or any network
[sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”] //This line of code will load image/resource from internet
r, _ := fyne.LoadResourceFromURLString("http://placekitten.com/g/200/300")
[/sourcecode] [sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”] // This line will show the image on canvas
img := canvas.NewImageFromResource(r)
[/sourcecode]

You can use these 2 apis for free images
[sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false”] // CAT API Free — http://placekitten.com/g/200/300
// New Random image URL https://picsum.photos/200
[/sourcecode]

[sourcecode lang=”go” autolinks=”false” classname=”myclass” collapse=”false” firstline=”1″ gutter=”true” highlight=”1-3,6,9″ htmlscript=”false” light=”false” padlinenumbers=”false” smarttabs=”true” tabsize=”4″ toolbar=”false” title=”Source Code main.go”]

package main

// import fyne
import (
"image/color"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
)

func main() {
// New app
a := app.New()
// New Title and Window
w := a.NewWindow("Load images from internet")
// loading images/assets/icons from computer
//r, _ := plugin.LoadResourceFromPath("c:/assets/tree.jpg")

// Images/assets from internet
//r, _ := plugin.LoadResourceFromURLString("https://picsum.photos/200")
r, _ := fyne.LoadResourceFromURLString("http://placekitten.com/g/200/300")
// CAT API Free — http://placekitten.com/g/200/300
// New Random image URL https://picsum.photos/200
img := canvas.NewImageFromResource(r)
textx:= canvas.NewText("my text change font", color.Black)
textx.TextStyle=

// Resize
w.Resize(fyne.NewSize(400, 400))

// Show and Setup content
w.SetContent(img)
w.ShowAndRun()
}

[/sourcecode]

[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/main26.go” text=”Download Code” color=”red_darker”]

[easy_media_download url=”http://blogvali.com/wp-content/uploads/fyne-golang-downloads/reso.go” text=”Resource” color=”red_darker”]

 

Fyne Golang GUI Course

Tony BB
 

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: