I was previously using the following code to change an icon on a custom toolbar:
(Note that the FlipBoard() Sub is my own and simply demonstrates how the old code was called.)
Sub FlipBoard()
Dim oImageMgr
Dim ImageURL, sCmdID As String
sCmdID = "vnd.sun.star.script:Standard.Chess.FlipBoard?language=Basic&location=document"
If DiagFlipped = FLIP_OFF Then
DiagFlipped = FLIP_ON
ImageURL = "file:///C:/Users/Public/OoChess/imgs2/FlipBIcon.gif"
Else
DiagFlipped = FLIP_OFF
ImageURL = "file:///C:/Users/Public/OoChess/imgs2/FlipWIcon.gif"
Endif
SetIconImage(sCmdID, ImageURL)
End Sub
' ----------------------------------------------- Not my code!
Sub SetIconImage(sCmdID As String, ImgURL As String)
Dim oImageMgr
On Error Goto ErrorHandler
oImageMgr = ThisComponent.getUIConfigurationManager().getImageManager()
Dim oImageCmds(0)
Dim oImages(0)
Dim oImage
REM Try to load the image from the file URL
oImage = GetImageFromURL(ImgURL)
If Not isNull(oImage) Then
REM *** Insert new image into the Writer image manager
oImageCmds(0) = sCmdID
oImages(0) = oImage
oImageMgr.replaceImages(0, oImageCmds(), oImages())
Else
MsgBox("Sorry. The image is Null!")
End If
Exit Sub
ErrorHandler:
MsgBox("An Error occurred while trying to set the toolbar icon", 16, "Set Icon Image")
On Error Goto 0 ' Reset error handling
End Sub
' ----------------------------------------------- Not my code!
Function GetImageFromURL( URL as String ) as Variant
Dim oMediaProperties(0) As New com.sun.star.beans.PropertyValue
Dim sProvider$ : sProvider = "com.sun.star.graphic.GraphicProvider"
Dim oGraphicProvider
On Error Goto ErrorHandler
REM Create graphic provider instance to load images from files.
oGraphicProvider = createUnoService(sProvider)
REM Set URL property so graphic provider is able to load the image
oMediaProperties(0).Name = "URL"
oMediaProperties(0).Value = URL
REM Retrieve the com.sun.star.graphic.XGraphic instance
GetImageFromURL = oGraphicProvider.queryGraphic(oMediaProperties())
Exit Function
ErrorHandler:
MsgBox("Can't retrieve image", 16, "Get Image From URL")
GetImageFromURL = Null
On Error Goto 0 ' Reset error handling
End Function
The GetImageFromURL Function now seems to return a Null instead of the image. Any ideas why this old code no longer works?
My Info:
LO: 7.4.5
OS: Windows 11