我有一个如下所示的人员类,其中有一个图像作为属性。我试图弄清楚如何在我的程序类中创建 person 类的实例,并将对象的图像设置为文件路径,例如C:\Users\Documents\图片.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;
}
}
最佳答案
像这样尝试:
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");
关于c# - 将图像属性设置为文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17450415/