6

I don't understand why I cannot display an image in WPF. Maybe I modified my resources folder accidentally and that is the reason why I does not get displayed. So I created a new wpf application and I have this:

enter image description here

and when I run the program my picture gets displayed as:

enter image description here

Why is it that when I try doing the same thing in my program the image does not show up!?

enter image description here

note how when I run the program there is no image...

enter image description here

In my other application I just dragged the image control to my main window and then I browsed for a random image on my computer and when I complied and run it it works fine. Why is it that I cannot do the same with the application that I am working with?


EDIT:

with some images it works and with others it does not! why?

take a look:

enter image description here

and when I compile and run one image does not show up!

enter image description here

and also take a look and see how the files have the same properties.

settings for folder image:

enter image description here

settings for mov image:

enter image description here

Tono Nam
  • 34,064
  • 78
  • 298
  • 470

3 Answers3

14

Chances are the Image does not have the Build Action set to Resource. If it's anything else, including Embedded Resource, then it will not display properly at runtime.

Other things you can check are the the resolution of the image. In Paint, you'd use File>Properties to view the resolution.

Try saving as a different format, such as jpg. If that works, then it's likely a problem with your file.

You may need to clean and rebuild your solution as well.

CodeNaked
  • 40,753
  • 6
  • 122
  • 148
  • It is set to resource just as the one like the other project and still does not show up. But plus by defauls it should appear. This is really strange – Tono Nam Jun 21 '11 at 21:06
  • @Tono - Added a few more things you can check, but otherwise it would help if you can post a small sample that reproduces your issue. – CodeNaked Jun 22 '11 at 00:14
  • 1
    Thanks @CodeNaked, I had this problem and clean & rebuild solution did the trick. – solarc Feb 02 '16 at 19:34
1

I fix it and I don't understand why it works. I need to add this information for my sqllite connection to work. I just had to comment this out:

enter image description here

and it worked. Maybe this is a bug of sqllite that I should report because those lines where added when creating the connection with visual studio.

Tono Nam
  • 34,064
  • 78
  • 298
  • 470
0

.BMP Image format is not supported. I had the same issue but after converting the image to .jpeg format it worked properly.

  • It looks like all the images are .png files according to the screenshots in the question... I don't think this is the correct answer to the original question. – Jeff B Aug 10 '16 at 16:09