C#向图像添加额外的属性/信息
我想向图像添加额外的属性或信息。 我尝试使用一个新类来获取图像属性,我只是添加了一个,但我不知道如何做到这一点 此外,我不能使用已经在使用的属性“标记”,也不能被覆盖C#向图像添加额外的属性/信息,c#,wpf,image,C#,Wpf,Image,我想向图像添加额外的属性或信息。 我尝试使用一个新类来获取图像属性,我只是添加了一个,但我不知道如何做到这一点 此外,我不能使用已经在使用的属性“标记”,也不能被覆盖 public partial class myImage : System.Windows.Controls.Image { //? } 认为你有一个形象 Image img = Image.FromFile("C:\\temp\\smth\\smth.jpg"); 使用系统图形获取propertyitem
public partial class myImage : System.Windows.Controls.Image
{
//?
}
认为你有一个形象
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);
将属性添加到从Image派生的类中,如下所示:
public class MyImage : Image
{
public string AdditionalInfoProperty { get; set; }
}
您还可以创建一个属性来保存ImageSource
对象:
public class MyImage
{
public ImageSource Image { get; set; }
public string AdditionalInfoProperty { get; set; }
}
然后在您的xaml中,您可以这样使用它,假设DataContext
包含类型为MyImage
的对象
<Image Source="{Binding Image}"/>
<TextBlock Text="{Binding AdditionalInfoProperty}"/>
获取或设置表示图像作者的值
public System.Collections.ObjectModel.ReadOnlyCollection<string> Author { get; set; }
public System.Collections.ObjectModel.ReadOnlyCollection作者{get;set;}
下面的代码示例演示如何使用BitmapMetadata类的友好属性将元数据写入位图图像
FileStream stream3 = new FileStream( "image2.tif", FileMode.Create );
BitmapMetadata myBitmapMetadata = new BitmapMetadata( "tiff" );
TiffBitmapEncoder encoder3 = new TiffBitmapEncoder();
myBitmapMetadata.ApplicationName = "Microsoft Digital Image Suite 10";
myBitmapMetadata.Author = new ReadOnlyCollection<string>(
new List<string>() { "Mehdi Daustany" } );
myBitmapMetadata.CameraManufacturer = "Tailspin Toys";
myBitmapMetadata.CameraModel = "TT23";
myBitmapMetadata.Comment = "Nice Picture";
myBitmapMetadata.Copyright = "2010";
myBitmapMetadata.DateTaken = "5/23/2010";
myBitmapMetadata.Keywords = new ReadOnlyCollection<string>(
new List<string>() { "Mehdi", "Daustany" } );
myBitmapMetadata.Rating = 5;
myBitmapMetadata.Subject = "Mehdi";
myBitmapMetadata.Title = "Mehdi's photo";
// Create a new frame that is identical to the one
// from the original image, except for the new metadata.
encoder3.Frames.Add(
BitmapFrame.Create(
decoder2.Frames[0],
decoder2.Frames[0].Thumbnail,
myBitmapMetadata,
decoder2.Frames[0].ColorContexts ) );
encoder3.Save( stream3 );
stream3.Close();
filestream3=newfilestream(“image2.tif”,FileMode.Create);
BitmapMetadata myBitmapMetadata=新的BitmapMetadata(“tiff”);
TiffBitmapEncoder encoder3=新的TiffBitmapEncoder();
myBitmapMetadata.ApplicationName=“Microsoft数字图像套件10”;
myBitmapMetadata.Author=新的只读集合(
新列表(){“Mehdi Daustani”});
myBitmapMetadata.CameraManufacturer=“Tailspin玩具”;
myBitmapMetadata.CameraModel=“TT23”;
myBitmapMetadata.Comment=“漂亮的图片”;
myBitmapMetadata.Copyright=“2010”;
myBitmapMetadata.datetake=“5/23/2010”;
myBitmapMetadata.Keywords=新建只读集合(
新列表({“Mehdi”,“Daustani”});
myBitmapMetadata.Rating=5;
myBitmapMetadata.Subject=“Mehdi”;
myBitmapMetadata.Title=“Mehdi的照片”;
//创建与该框架相同的新框架
//来自原始图像,新元数据除外。
编码3.帧。添加(
BitmapFrame.Create(
解码2.帧[0],
decoder2.Frames[0]。缩略图,
myBitmapMetadata,
decoder2.Frames[0].ColorContexts));
编码3.保存(流3);
stream3.Close();
问题是关于WPF的。所以我正在使用一个数据库,我想添加一个int(Person\u ID),这样我就可以直接看到哪个图像属于哪个人,而无需再次使用数据库。保存文件时,可以将Id添加到文件的路径中。这是一种方法,然后可以使用SetProperty attr添加Id属性项中的一个属性项。您指的是依赖性属性吗,或者您实际上不知道如何在C#类声明中编写属性吗?System.Windows.Controls.Image
无法分配给Image.Source
属性。应该是ImageSource,你应该解释一下区别。请告诉我你到底认为INPC是什么(当你只有自动实现的属性时,它可能有什么用处)。谢谢你的意见。哇!别紧张。答案的要点是展示实现属性的方法以及如何将它们用作解决方案。我承认这些信息不是100%正确的,但是没有必要用严厉的语言。当然,但它可以很容易地被纠正。我会为你做的。