Author Topic: Image from resources (Embedded in .resx)  (Read 2089 times)

0 Members and 1 Guest are viewing this topic.

djee

  • Newt
  • Posts: 49
Image from resources (Embedded in .resx)
« on: January 23, 2017, 02:59:42 PM »
I'm trying to use an image from my resources (Embedded in .resx) for one of my WPF button. Nothing is working... I can see the image in my designer but not when executing... The image resource is of type Bitmap.  I've tried lots of different scenario & can't get anything going. Anybody has experience using images from resources? :crazy2:

NOT working:
Code: [Select]
Dim myAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
Dim myStream As Stream = myAssembly.GetManifestResourceStream("FreezeOn.png")
Dim image As New Bitmap(myStream)

my XAML
Code: [Select]
  <Button Name="ScanFile">
                <StackPanel>
                    <Image Name="myExitImage"  Source="pack://siteoforigin:,,,/Resources/FreezeOn.png"/>
                </StackPanel>
            </Button>
« Last Edit: January 23, 2017, 03:38:42 PM by djee »

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Image from resources (Embedded in .resx)
« Reply #1 on: January 23, 2017, 03:20:49 PM »
I don't have many images saved as resources, but I did find this one.

Bobby C. Jones

djee

  • Newt
  • Posts: 49
Re: Image from resources (Embedded in .resx)
« Reply #2 on: January 23, 2017, 03:34:50 PM »
Is the persistence setting of your image set to: Embedded in .resx? I`m guessing everything is fine on your side of thing (you can see the image)? If you copy your app to another directory, do you still see the resource image ?


Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Image from resources (Embedded in .resx)
« Reply #3 on: January 23, 2017, 04:20:06 PM »
Is the persistence setting of your image set to: Embedded in .resx? I`m guessing everything is fine on your side of thing (you can see the image)? If you copy your app to another directory, do you still see the resource image ?

It's not listed in the .resx file, just set as Resource for the build action.
Bobby C. Jones

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Image from resources (Embedded in .resx)
« Reply #4 on: January 23, 2017, 04:20:53 PM »
I`m guessing everything is fine on your side of thing (you can see the image)? If you copy your app to another directory, do you still see the resource image ?

Sorry, yes and yes.
Bobby C. Jones

djee

  • Newt
  • Posts: 49
Re: Image from resources (Embedded in .resx)
« Reply #5 on: January 23, 2017, 05:18:18 PM »
Thanks to the image you've posted, I just saw the BUILD ACTION comboBox menu... As you've mention, I just changed the build action to ''Ressource'' & all is fine... I won't tell you how much time I lost trying to figure this one out...  :whistling:
Thanks a bunch!