0

I'm downloading and saving images from URL. The image can be of any format. Right click on the image, select Properties and then the Details tab. There is a Comments field. I would like to add text in that field while saving the image . Is it possible.

using (WebClient webClient = new WebClient())
{
  webClient.DownloadFile("http://www.example.com/1.jpg", "1.jpg");
 }

enter image description here

leppie
  • 115,091
  • 17
  • 196
  • 297
sukesh
  • 2,379
  • 12
  • 56
  • 111
  • 3
    Look at this: [link](http://dejanstojanovic.net/aspnet/2014/november/adding-extra-info-to-an-image-file/) – Legends Jun 10 '16 at 19:18
  • no it is not the same he need 1) download an ANY imge from a link. it can be tiff, jpg, png etc. 2) he need to decode the image to read the image raw data 3) he need to create an jpg which contains the raw data and the metadata which u have given the referance. – Bassam Alugili Jun 10 '16 at 19:54

2 Answers2

2

The property system in Windows has a complex story, you can find more information about it here: Extracting Windows File Properties (Custom Properties) C#

You could try it with the Microsoft.WindowsAPICodePack.Shell nuget package:

  var file = ShellFile.FromFilePath("your image.jpg");
  using (var writer = file.Properties.GetPropertyWriter())
  {
      writer.WriteProperty(file.Properties.System.Comment, "hello");
  }

But, in the case of images, the shell may not be able to write extra properties on the file itself (most imaging codecs except JPG don't support such a 'comments' metadata). What I suggest in this case is use this CodeFluentRuntime nuget package's CompoundStorage class, here is an example:

static void Main(string[] args)
{
    var storage = new CompoundStorage("your image.png", false); // open for write
    storage.Properties.Comments = "hello"; // change well-known "comments" property
    storage.CommitChanges();
}

It will work and write the property information not stricly on the file, but on NTFS (it works also on pure plain .txt files for example). If you read the file again and browse all properties, like this, you should see it:

static void Main(string[] args)
{
    var storage = new CompoundStorage("consent.png"); // open for read
    foreach (var prop in storage.Properties)
    {
        Console.WriteLine(prop.Name + "=" + prop.Value);
    }
}

Now, the problem is, with recent versions of Windows, the shell property sheet you show in your question will not display the Comments property (for example, I'm running on Windows 10 and I don't see it although it's properly written). Unfortunately, there is not many other options for images files.

Community
  • 1
  • 1
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
0

You can use this reference link to solved your problem.

http://www.codeproject.com/Articles/3615/File-Information-using-C

Jahed Kabiri
  • 115
  • 5