我想添加一个额外的属性或信息到图像。 我尝试使用一个新的类,获取图像propertys,我只是添加一个,但我不知道如何做到这一点。C#为图像添加额外的属性/信息
而且我不能已经使用属性“标签”,多数民众赞成在使用,不能被覆盖
public partial class myImage : System.Windows.Controls.Image
{
//?
}
我想添加一个额外的属性或信息到图像。 我尝试使用一个新的类,获取图像propertys,我只是添加一个,但我不知道如何做到这一点。C#为图像添加额外的属性/信息
而且我不能已经使用属性“标签”,多数民众赞成在使用,不能被覆盖
public partial class myImage : System.Windows.Controls.Image
{
//?
}
添加属性从图像派生的类是这样的:
public class MyImage : Image
{
public string AdditionalInfoProperty { get; set; }
}
你也可以创建一个能够持有ImageSource
对象中的属性:在您的XAML
public class MyImage
{
public ImageSource Image { get; set; }
public string AdditionalInfoProperty { get; set; }
}
然后假设DataContext
包含MyImage
类型的对象,则可以这样使用它。
<Image Source="{Binding Image}"/>
<TextBlock Text="{Binding AdditionalInfoProperty}"/>
考虑你有一个形象
Image img = Image.FromFile("C:\\temp\\smth\\smth.jpg");
使用系统图的获得propertyitem
System.Drawing.Imaging.PropertyItem prop = img.PropertyItems[0];
设置信息
SetProperty(ref prop, 33432, "Test Info...");
img.SetPropertyItem(prop);
你是在谈论依赖项属性,还是你实际上不知道如何在C#类声明中编写属性? – Clemens