Load Image from Internet – Fyne GUI Golang tutorial 28

Want to load images from internet and local storage. It is very easy in fyne Golang GUI.

fyne display image from internet

Parse url and loading image form url
[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”] r, _ := fyne.LoadResourceFromURLString("https://picsum.photos/200")
[/sourcecode]
In this example we loading images from picsum site. You can use any.
you need to import canvas module and it will load images from the resource provided.
[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”] img := canvas.NewImageFromResource(r)
[/sourcecode]

fyne display image from your computuer

Want to load images from computer and local storage. It is very simple. use Image widget.

[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”]

img := canvas.NewImageFromFile("c:/assets/health.jpg")

[/sourcecode]

In this example we are loading image from assets director/folder in C drive.

[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 (
"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("Loading images from internet")
// resize
w.Resize(fyne.NewSize(400, 400))
// loading image form url
r, _ := fyne.LoadResourceFromURLString("https://picsum.photos/200")
img := canvas.NewImageFromResource(r)
w.SetContent(img)
//
w.ShowAndRun()
}

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

Fyne Golang GUI Course

fyne golang example to load images from internet, local storage computer. Golang fyne tutorial for beginners looking for source code with example.

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: