Click here to Skip to main content
15,914,608 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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#
Posted
Comments
Afzaal Ahmad Zeeshan 23-Oct-15 5:26am    
By altering the properties of that file.
MAYANK GEETE 23-Oct-15 5:40am    
Please explain little more .. or a sample code you have.

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.
C#
// 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
C#
// Shell sh = CreateShell();
// Creating a Folder Object from Folder that inculdes the File
Folder dir = GetShell32Folder(Path.GetDirectoryName(sFile));

You also need to add the method GetShell32Folder
C#
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 });
}

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.
 
Share this answer
 
v2
Comments
MAYANK GEETE 23-Oct-15 5:54am    
I tried this code

string path = "E:\\download.jpg";
Image image = Image.FromFile(path);
image.Tag = "Hello";
image.Save("E:\\Test.JPG");

But its not workin
MAYANK GEETE 23-Oct-15 5:56am    
Hello George Jonsson

// Create two images.
Image image1 = Image.FromFile("c:\\FakePhoto1.jpg");
Image image2 = Image.FromFile("c:\\FakePhoto2.jpg");

// Get a PropertyItem from image1.
PropertyItem propItem = image1.GetPropertyItem(20624);

// Change the ID of the PropertyItem.
propItem.Id = 20625;

// Set the PropertyItem for image2.
image2.SetPropertyItem(propItem);

// Draw the image.
e.Graphics.DrawImage(image2, 20.0F, 20.0F);

but in this code there no TAG Value
MAYANK GEETE 23-Oct-15 6:24am    
Please see this link

https://msdn.microsoft.com/en-us/library/system.drawing.image.tag(v=vs.110).aspx

why its not working
George Jonsson 23-Oct-15 8:33am    
See my updated answer.
Sorry, but my time is running out so you are on your own for the moment.
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 .
 
Share this answer
 
Comments
Member 14915867 19-Aug-20 1:10am    
Actually I am facing some issue when i updated tags value
Its updated when image has datetaken but in case of blank metadata tags not updated
Can you share your code
I hope it will work for me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900