LoadImage SVG format

Just starting out? Need help? Post your questions and find answers here.
Dirk Geppert
Posts: 275
Joined: Fri Sep 22, 2017 7:02 am

LoadImage SVG format

Post by Dirk Geppert »

hi folks,

how to load svg image and handle it? I would like to load the svg in a certain size for best quality

LoadImage() seems not work:

Code: Select all

 Procedure Loaded(Type, Filename$, ObjectId)
    ; Display the image in a new window
    OpenWindow(#PB_Any, 10, 10, 300, 300, "Image", #PB_Window_SizeGadget)
    ImageGadget(#PB_Any, 0, 0, ImageWidth(ObjectId), ImageHeight(ObjectId), ImageID(ObjectId))
    
  EndProcedure
  
  Procedure LoadingError(Type, Filename$, ObjectId)
    Debug Filename$ + ": loading error"
  EndProcedure
  
  ; Register the loading event before calling any resource load command
  BindEvent(#PB_Event_Loading, @Loaded())
  BindEvent(#PB_Event_LoadingError, @LoadingError())
  
  LoadImage(0, "https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg")

User avatar
Peter
Posts: 1068
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadImage SVG format

Post by Peter »

your code works here
Dirk Geppert
Posts: 275
Joined: Fri Sep 22, 2017 7:02 am

Re: LoadImage SVG format

Post by Dirk Geppert »

Thx Peter - seems then a firefox thingie..

But how can I load that svg with my prefered size?
User avatar
Peter
Posts: 1068
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: LoadImage SVG format

Post by Peter »

Dirk Geppert wrote: Mon Sep 11, 2023 10:54 amBut how can I load that svg with my prefered size?
I'm not sure if I understand you correctly, but you can run ResizeImage().

Code: Select all

Procedure Loaded(Type, Filename$, ObjectId)
  
  ; Display the image in a new window
  OpenWindow(0, 10, 10, 400, 400, "Image", #PB_Window_SizeGadget)
  ResizeImage(0, 300, 300)  
  ImageGadget(0, 10, 10, ImageWidth(0), ImageHeight(0), ImageID(0))
  
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
EndProcedure

; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())

LoadImage(0, "https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg")

Code: Select all

Enumeration
  #Window
EndEnumeration

Enumeration
  #ImageGadget
  #ButtonGadget
EndEnumeration

Enumeration
  #Image
EndEnumeration

Procedure ButtonGadgetEvent()
  
  If GetGadgetText(#ButtonGadget)="Bigger"
    ResizeImage(#Image, 300, 300)  
    SetGadgetText(#ButtonGadget, "Smaller")
  Else
    ResizeImage(#Image, 150, 150)  
    SetGadgetText(#ButtonGadget, "Bigger")
  EndIf
  
  SetGadgetState(#ImageGadget, ImageID(#Image))
  
EndProcedure

Procedure Loaded(Type, Filename$, ObjectId)
  
  ; Display the image in a new window
  OpenWindow(#Window, 10, 10, 400, 400, "Image", #PB_Window_SizeGadget)
  ImageGadget(#ImageGadget, 10, 10, ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))
  ButtonGadget(#ButtonGadget, 10, WindowHeight(#Window) - 40, 100, 30, "Bigger")
  BindGadgetEvent(#ButtonGadget, @ButtonGadgetEvent())
  
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
  Debug Filename$ + ": loading error"
EndProcedure

; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())

LoadImage(#Image, "https://upload.wikimedia.org/wikipedia/commons/0/02/SVG_logo.svg")
Dirk Geppert
Posts: 275
Joined: Fri Sep 22, 2017 7:02 am

Re: LoadImage SVG format

Post by Dirk Geppert »

The advantage of vector graphics is, that they can be scaled as desired and are always rendered 1a sharp.

This means that I would only need one graphic that adapts to the size of each end device and looks good.

With the current solution, the SVG is loaded in the standard resolution and converted into a bitmap. When the image is then resized, it looks blurry.
Post Reply