Loading Images

Assets can be added to your project as either files or embedded resources

In the startup of your project you need to set the Content Property of the Content Manager instance. This is normally named Content and is in the root of your project.

Assets will be loaded by their file name. For graphics, you can load by adding an extension or just by the name of the file. If you do not have an extension it will look for files by appending either .png or .bmp.

If you add the file Ball.png to the /Content directory, you can load the graphic with either:

This is useful if you target different types of platforms (ie Zune and Windows Mobile) with the Zune your content will be compiled to an XNB file for the XNA runtime to load where Windows Mobile will load with the actual bitmap.

Providing graphics for different DPIs to provide better resolution

In addition for Windows Mobile you can load different files based upon DPI, that is to say you can have one graphic that looks good for 96DPI for a 320x240 resolution and another for 800x480 with a typical DPI of 192 to do this.
  1. Add your default image directly to the /Content directory
  2. Create a directory off of /Content called 192 (or the DPI you want to target)
  3. Add the higher resolution graphics to the the /Content/192 directory.

Providing graphics specific for Windows Mobile

To provide graphics specifically for Windows Mobile that are not in a DPI directory, place them in a directory called wm - Example /Content/wm/Ball.png.

So when the content manager looks for the graphic Ball it will search the directories in the following order:

When loading content, the engine will first search for content based upon the current DPI; usually either /Content/96 or /Content/192 if it doesn't find the asset in that directory it will look in the default directory /Content


By default Windows Mobile doesn't know about the Alpa channel in your graphic, and will render and transparent pixels as white. To render a transparent image, after you load the image, set the ColorKey to the color you want to be transparent. If you are using a PNG with tranparency, set the ColorKey = Color.White. It should be noted that rendering images with this method is not as efficient as rendering the image without the ColorKey set. If you have a solid background consider setting the transparent portion of the image to the color of the background.

Last edited Jan 12, 2010 at 1:03 AM by kevindwolf, version 6


No comments yet.