Older Macro Code to Change Toolbar Icon No Longer Works

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"
      DiagFlipped = FLIP_OFF
      ImageURL = "file:///C:/Users/Public/OoChess/imgs2/FlipWIcon.gif"
   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())
         MsgBox("Sorry. The image is Null!")
      End If
   Exit Sub

  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

  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

Please add the version of your SO and LibreOffice.

I test only your function GetImageFromURL and work fine in my system.

PATH = ConvertToURL("/home/elmau/Projects/test/img/update.png")
image = GetImageFromURL(PATH)
MsgBox IsNull(image)

Are you sure the paths are correct?

Version: (X86_64) / LibreOffice Community
Build ID: 50(Build:2)
CPU threads: 16; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: es-MX (en_US.UTF-8); UI: en-US
Calc: threaded

I test all your code. If I used 0 in first argument of method replaceImages not happen nothing, but, if change for 1, work fine.

	CMD = "vnd.sun.star.script:test.py$test_1?language=Python&location=user"	
	PATH = ConvertToURL("/home/elmau/Projects/test/img/update.png")
	image = GetImageFromURL(PATH)
    manager = ThisComponent.UIConfigurationManager.ImageManager
   	manager.replaceImages(1, Array(CMD), Array(image))

Hi elmau. Thanks very much for this. Changing the value from 0 to 1 was the answer to my problem. The code that I posted was from an old template I wrote in OpenOffice, about ten years ago. I’m very grateful to have it working again as the ability to change an icon to reflect the current status of the underlying feature is really important. Thanks again!