Page 1 of 1
LoadImage SVG format
Posted: Mon Sep 11, 2023 10:10 am
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")
Re: LoadImage SVG format
Posted: Mon Sep 11, 2023 10:24 am
by Peter
your code works here
Re: LoadImage SVG format
Posted: Mon Sep 11, 2023 10:54 am
by Dirk Geppert
Thx Peter - seems then a firefox thingie..
But how can I load that svg with my prefered size?
Re: LoadImage SVG format
Posted: Mon Sep 11, 2023 2:52 pm
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")
Re: LoadImage SVG format
Posted: Tue Sep 12, 2023 11:09 am
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.