In WPF, you should use the ImageSource
class, like this:
public class Hero {
public string Name { get; set; }
public string HeroType { get; set; }
public int StartingHP { get; set; }
public int StartingMana { get; set; }
public Dictionary<string, string> Spells { get; set; }
public Dictionary<string, string> Items { get; set; }
public ImageSource Portrait { get; set; }
}
You can read an image from a file like this:
myHero.Portrait = new BitmapImage(new Uri(filePath, UriKind.Absolute));
You can use the Image
class from System.Drawing.dll. For example:
public class Hero {
public string Name { get; set; }
public string HeroType { get; set; }
public int StartingHP { get; set; }
public int StartingMana { get; set; }
public Dictionary<string, string> Spells { get; set; }
public Dictionary<string, string> Items { get; set; }
public Image Portrait { get; set; }
}
To load the image, call Image.FromFile(path)
. If you have an image in a stream (eg, from a database or web service, you can call Image.FromStream(stream)
.
If you have all of the images at compile time, you can put them in a ResX file; you can get an image from the designer-generated code file like this: myHero.Portrait = SomeResXFile.Portrait1
.