I was beginning to believe that I was just being stupid... missing some obvious thing, or misspelling something, or otherwise having fumble fingers...
So I copied and pasted the code suggestions and still had issues... the issues were always in not obtaining the stream from the passed in image name string in the addImage function...
Mustafa's (and Louis's VB conversion of it) call the function by supplying a string consisting of:
Namespace.Resources.Imagename.ext
Then I got to digging around in Jeremy's posted examples and realized a difference... I took out the "Resources." in calls to the function and everything works as it should:
Namespace.Imagename.ext
so (in Louis' VB conversion):
pushButton1.LargeImage = PNGtoImageSource("RevitTest.Resources.Update-32.png")
pushButton1.Image = PNGtoImageSource("RevitTest.Resources.Update-16.png")
becomes:
pushButton1.LargeImage = PNGtoImageSource("RevitTest.Update-32.png")
pushButton1.Image = PNGtoImageSource("RevitTest.Update-16.png")
Thanks guys... I don't know whom to credit the solution to since it was bits and pieces from all of you... but I do have a solution and it was the 3 of you that got me there. Here's the function that I ended up with:
Private Function addImage(imageName As String) As ImageSource
'required imports:
'System.Windows.Media
'System.IO
Dim imageStream As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(imageName)
Dim imgDecoder
Select Case LCase(Path.GetExtension(imageName))
Case Is = ".png"
imgDecoder = New Imaging.PngBitmapDecoder(imageStream, Imaging.BitmapCreateOptions.PreservePixelFormat, Imaging.BitmapCacheOption.Default)
Case Is = ".bmp"
imgDecoder = New Imaging.BmpBitmapDecoder(imageStream, Imaging.BitmapCreateOptions.PreservePixelFormat, Imaging.BitmapCacheOption.Default)
Case Is = ".jpg"
imgDecoder = New Imaging.JpegBitmapDecoder(imageStream, Imaging.BitmapCreateOptions.PreservePixelFormat, Imaging.BitmapCacheOption.Default)
Case Else 'icons
imgDecoder = New Imaging.IconBitmapDecoder(imageStream, Imaging.BitmapCreateOptions.PreservePixelFormat, Imaging.BitmapCacheOption.Default)
End Select
addImage = imgDecoder.Frames(0)
End Function
Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr
aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)