我想添加一個額外的屬性或信息到圖像。 我嘗試使用一個新的類,獲取圖像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