Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

Can anyone help me please, I am trying to add some images to my application but this is the first time I have used WPF and am a little lost.

I have some JPEG images that I have loaded into my application as resources so that I don't have to point to file paths in my code anywhere.

I then have an array list of objects, all of which are objects that I have created. Each object as a variable called oLocation which points to the relevant picture in the resources list.

I want the program to display a certain image when it loads up but then this image will change on the press of a button.

I have looked everywhere but whatever I try doesn't seem to work, I have looked at using the image element but when I set the source to the oLocation variable it get this erroer "Unable to cast object of type 'System.Drawing.Bitmap' to type 'System.Windows.Media.Imaging.BitmapImage'."

here is how I am trying to do it
VB
Dim ib As New BitmapImage
ib.BeginInit()
ib = QuestionList(iCounter).Location()
ib.EndInit()
Image1.Source = ib

This is where I have pointed to the resource in the program
VB
GQ = New GifQuestion(My.Resources.Resource1.resource1, "Has Been", "Added")

GifQuestion is my own class and resource1 is an image in the resource list and "Has Been" & "Added" are just two strings to fill space as I have been testing using the output window.
GQ is contained within the QuestionList() array list.

Can anyone pointme in the right direction please, I am very confused by this.

Thanks in Advance

Dave
Posted
Comments
Sergey Alexandrovich Kryukov 2-Jun-13 14:16pm    
Where is your question? "Can anyone..."? Not really a question.

You did not explain your problem. And, essentially, who knows what "ib = QuestionList(iCounter).Location()" does? Without showing it, this post is pretty much useless...

—SA
Prasad Khandekar 2-Jun-13 15:22pm    
Hello Dave,

Perhaps this thread provides answer to your question (http://www.codeproject.com/Questions/349920/Images-in-WPF-as-embedded-resources).

Regards,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900