#275 – Load a Loose Image File into an Image Control

You can distribute an image file as a loose file, i.e. deploy it as a separate file along with your executable, and then load the image into an Image control at runtime.  To do this:

  • Add the image file to your project
  • Set the image file’s Build Action to Content
  • Use a plain filename as the image’s Source
  • Distribute the image file with the executable

Add the image (.png) file to the project.

Set the Build Action to Content.  The image resource won’t be embedded in the .exe file, but the project will know where to find the file.  Also set the Copy to Output Directory field, so that the file is copied.

Use the plain filename as the Source.

<Image Source="TractorSm.png"/>

Distribute the image file along with the executable.  (When you build the project, the file will be automatically copied to the output directory).

About these ads

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 377 other followers

%d bloggers like this: