4

以下のような人物クラスがあり、画像を属性として持っています。プログラム クラスで person クラスのインスタンスを作成し、オブジェクトのイメージをファイルパス (例: C:\Users\Documents\picture.jpg) に設定する方法を見つけようとしています。これについてどうすればいいですか?

 public class Person
 {
    public string firstName { get; set; }
    public string lastName { get; set; }
    public Image myImage { get; set; }

    public Person()
    {
    }

    public Person(string firstName, string lastName, Image image)
    {
        this.fName = firstName;
        this.lName = lastName;
        this.myImage = image;
    }
 }
4

4 に答える 4

1

次のようにしてみてください。

public class Person
 {
    public string firstName { get; set; }
    public string lastName { get; set; }
    public Image myImage { get; set; }
    public Person()
    {
    }
    public Person(string firstName, string lastName, string imagePath)
    {
       this.fName = firstName;
       this.lName = lastName;
       this.myImage = Image.FromFile(imagePath);
    }
}

そして、次のようにインスタンス化します。

Person p = new Person("John","Doe",@"C:\Users\Documents\picture.jpg");
于 2013-07-03T14:19:37.913 に答える