Hi guys,
because of the better quality and scalability I would like to use SVG images instead of PNG.
I would like to be able to draw a number in the image (cluster icon - number of elements).
Is there a way to load an SVG as an image so that I can draw on it with SB functions?
Kind regards
Dirk
Load and work SVG Images
Re: Load and work SVG Images
You can load a SVG with LoadImage():Dirk Geppert wrote: ↑Thu Nov 24, 2022 3:50 pmIs there a way to load an SVG as an image so that I can draw on it with SB functions?
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)
ResizeImage(ObjectId, 300, 300)
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://svgsilh.com/svg_v2/1801287.svg")
-
- Posts: 284
- Joined: Fri Sep 22, 2017 7:02 am
Re: Load and work SVG Images
Mmh, I had tried it with the following SVG image. Unfortunately, it does not work.
Code: Select all
https://www.vvo-online.de/tools/weihnachtsmarkt/PuR.svg
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)
ResizeImage(ObjectId, 300, 300)
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://www.vvo-online.de/tools/weihnachtsmarkt/PuR.png")
LoadImage(0, "https://www.vvo-online.de/tools/weihnachtsmarkt/PuR.svg")
Re: Load and work SVG Images
works in Chrome and Edge as expected:
Firefox reports the following:
Firefox reports the following:
This requires some detective work.Uncaught DOMException: CanvasRenderingContext2D.drawImage: Passed-in canvas is empty
-
- Posts: 284
- Joined: Fri Sep 22, 2017 7:02 am
Re: Load and work SVG Images
Thank you Peter.
It is good to know that basically SVG images can be loaded with SB functions.
It is therefore necessary to check whether the image can be loaded correctly everywhere....
It is good to know that basically SVG images can be loaded with SB functions.
It is therefore necessary to check whether the image can be loaded correctly everywhere....
Re: Load and work SVG Images
I can confirm the error/behaviour:
FireFox 107.0.1 (64-Bit) on macOS Monterey, 12.6.1, Intel CPU.
On Safari it works, though.
FireFox 107.0.1 (64-Bit) on macOS Monterey, 12.6.1, Intel CPU.
On Safari it works, though.
-
- Posts: 284
- Joined: Fri Sep 22, 2017 7:02 am
Re: Load and work SVG Images
Since Firefox can load and display the image directly, but not with SB LoadImage() ... where is the error then? With SpiderBasic?