C# msdn示例提取元数据
试着恢复速度。如果这是一个过于简单的问题,那么很抱歉 我已经从MSDN创建了C# msdn示例提取元数据,c#,call,C#,Call,试着恢复速度。如果这是一个过于简单的问题,那么很抱歉 我已经从MSDN创建了PictureViewer示例,并试图添加一些额外的功能。具体来说,我正在尝试从图像文件中读取和显示特定的元数据 在试图理解示例时,我似乎需要链接一个表单控件来调用示例代码。但我不明白这个电话应该是什么样子。放置 ExtractMetadata(e); in an event handler giving me a error 参数1:无法从“System.EventArgs”转换为 'System.Windows.F
PictureViewer
示例,并试图添加一些额外的功能。具体来说,我正在尝试从图像文件中读取和显示特定的元数据
在试图理解示例时,我似乎需要链接一个表单控件来调用示例代码。但我不明白这个电话应该是什么样子。放置
ExtractMetadata(e); in an event handler giving me a error
参数1:无法从“System.EventArgs”转换为
'System.Windows.Forms.PaintEventArgs'
我是否缺少“此”
”指针或其他什么
///////////////////我想我需要更多的信息。如果查看注释ExtractMetadata顶部的链接,它是一个从图像文件获取EXIF数据(可交换图像文件)的调用,但它需要PaintEventArgs e,这是Paint事件处理程序的一个参数,因此它需要System.Drawing.Imaging命名空间 下面是示例提供的代码,我正在尝试执行:
private void ExtractMetaData(PaintEventArgs e)
{
try
{
// Create an Image object.
Image theImage = new Bitmap("C:\\Users\\DadPC\\Desktop\\testrunfiles\\fakePhoto.jpg");
// Get the PropertyItems property from image.
PropertyItem[] propItems = theImage.PropertyItems;
// Set up the display.
Font font1 = new Font("Arial", 10);
SolidBrush blackBrush = new SolidBrush(Color.Black);
int X = 0;
int Y = 0;
// For each PropertyItem in the array, display the id,
// type, and length.
int count = 0;
foreach (PropertyItem propItem in propItems)
{
e.Graphics.DrawString("Property Item " +
count.ToString(), font1, blackBrush, X, Y);
Y += font1.Height;
e.Graphics.DrawString(" ID: 0x" +
propItem.Id.ToString("x"), font1, blackBrush, X, Y);
Y += font1.Height;
e.Graphics.DrawString(" type: " +
propItem.Type.ToString(), font1, blackBrush, X, Y);
Y += font1.Height;
e.Graphics.DrawString(" length: " +
propItem.Len.ToString() +
" bytes", font1, blackBrush, X, Y);
Y += font1.Height;
count += 1;
}
font1.Dispose();
}
catch (Exception)
{
MessageBox.Show("There was an error." +
"Make sure the path to the image file is valid.");
}
}
在我的forms应用程序中,我一直在试图找出如何调用该函数
private void metadataButton_Click(object sender, EventArgs e)
{
ExtractMetaData(e);
}
但这正是我不成功的地方,我没有弄清楚它希望我通过什么,包括什么都不尝试(try nothing ExtractMetaData()
长期以来,我希望读取特定的元数据并将其右转到图像文件中,但我正在使用MSDN的这个示例开始
此代码旨在从绘制事件处理程序调用。它使用当时可用的图形对象直接绘制到显示器上。大概是这样的:
private void Form1_Paint(object sender, PaintEventArgs e)
{
ExtractMetadata(e);
}
事件处理程序通常添加到VisualStudio设计器中。但它会将此行添加到Designer.cs文件:
private void InitializeComponent()
{
...
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
...
}
您也可以在构造函数中手动添加这行代码(在调用InitializeComponent之后)您可以显示从中调用
提取元数据的处理程序吗?