Load Display Image from Internet – Fyne GUI Golang tutorial 28

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
r, _ := fyne.LoadResourceFromURLString("https://picsum.photos/200")
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.
    img := canvas.NewImageFromResource(r)

fyne display image from your computuer

Want to load images from computer and local storage. It is very simple. use Image widget.
img := canvas.NewImageFromFile("c:/assets/health.jpg")

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

 

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()
}

Download Code

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: