如何使用c#更改图像文件的TAG [英] How to change TAG of a image file using c#

查看:87
本文介绍了如何使用c#更改图像文件的TAG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图像中添加一些TAG使用c#





[标签在哪里?]

右键单击任何图像 - >

点击属性 - >

在属性窗口中点击Details->

在描述中你可以看到TAG



那么如何使用C#更改此TAG

i want to add some TAG in image using c#


[Where is TAG ?]
Right click on any image ->
Click on properties ->
In properties window click on Details->
In Description you can see TAG

So how to change this TAG using C#

推荐答案

请参阅下面的更新答案。



(您可以检索现有属性项并更改值。

请参阅 Image.GetPropertyItem方法 [ ^ ]

有一个小例子可以关注。



此信息可用于获取身份证号码图像属性标记常量 [ ^ ]



另请参阅此Stack Overflow问题:如何获取和设置图像的属性项 [ ^ ])



[更新]

首先。 Image.Tag属性与详细属性无关。它通常用于携带有关代码内对象的额外信息。它没有保存到文件中。



因为我没有正确地阅读你的问题所以我把你带入歧途。经过一些研究后我发现了以下内容:



要阅读详细信息,本文将非常有用。

检索文件的详细信息 [ ^ ]

注意! 直接使用演示代码将无法在Windows 8或更高版本下运行。

您必须修改如何获取文件夹信息。



在文件 CfileInfo.cs 中,您需要在方法 GetDetailedFileInfo 中更改以下行



See updated answer below.

(You can retrieve an existing property item and change the value.
See Image.GetPropertyItem Method[^]
There is a little example you can follow there.

This information can be useful for getting the ID number Image Property Tag Constants[^]

Also see this Stack Overflow question: How to get and set propertyitems for an image[^])

[UPDATE]
First. The Image.Tag property has nothing to do with the detailed properties. It is usually used to carry extra information about an object inside the code. It is not saved to the file.

I lead you astray as I didn't read your question properly. After some research I have found out the following.

To read the detailed information this article will be useful.
Retrieve detailed information of a File[^]
Note! Using the demo code directly will not work under Windows 8 or later.
You have to modify how to get the folder information.

In the the file CfileInfo.cs you need to change the following lines
in the method GetDetailedFileInfo.
// Creating a ShellClass Object from the Shell32
ShellClass sh = new ShellClass();
// Creating a Folder Object from Folder that inculdes the File
Folder dir = sh.NameSpace(Path.GetDirectoryName(sFile));



to


to

// Shell sh = CreateShell();
// Creating a Folder Object from Folder that inculdes the File
Folder dir = GetShell32Folder(Path.GetDirectoryName(sFile));



你还需要添加方法 GetShell32Folder


You also need to add the method GetShell32Folder

private Shell32.Folder GetShell32Folder(string folderPath)
{
    Type shellAppType = Type.GetTypeFromProgID("Shell.Application");
    Object shell = Activator.CreateInstance(shellAppType);
    return (Shell32.Folder)shellAppType.InvokeMember("NameSpace",
    System.Reflection.BindingFlags.InvokeMethod, null, shell, new object[] { folderPath });
}



这是我在这里找到的解决方法:在Windows 8中实例化Shell32.Shell对象 [ ^ ]



属性标签不包含在内,因此您需要在<$ c中的switch子句中添加一个案例$ c> CFileInfo 构造函数。我认为它应该是案例13,但我不确定,因为我没有要测试的文件。



CFileInfo 所有详细属性都是只读的,所以你需要自己添加设置功能。<​​br />
我目前没有更多时间处理这个问题,但如果可以,我会更新我的回答。只是不要屏住呼吸。


It's a workaround I found here: Instantiate Shell32.Shell object in Windows 8[^]

The property Tags is not included, so you need to add a case in the switch clause in the CFileInfo constructor. I think it should be case 13, but I am not sure because I have no file to test on.

In CFileInfo all the detailed properties are read only, so you need to add set functionality yourself.
I don't have more time to work on this question at the moment, but if I can I will update my answer. Just don't hold your breath.


感谢George Jonsson的回答...

我找到了另一种方法来做这件事。经过一整天的搜索我发现FOTOFLY.DLL

完全符合我的要求。
Thanks George Jonsson for your answer ...
I found another way to do this.After the whole day search i found FOTOFLY.DLL
which do exactly what i want .


这篇关于如何使用c#更改图像文件的TAG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆