Not all image properties obtained using Image.PropertyItems

I am trying to get a list of all the tags EXIFin this image. using an array Image.propertyItems[], I can list all the elements that the instance of the image object reads and display their identifier.

I see that there are elements that are NOT listed there, that other applications, including Windows Explorer, do not seem to have problems getting.

eg. in the following code ...

Image img = new Bitmap("C:\\IMAG0648.jpg");
foreach (PropertyItem property in img.PropertyItems)
  {
    Trace.WriteLine(property.Id);
  }

I get a list of most elements, especially if I don't have (among, perhaps others) 0x010Fand 0x0110. I know that these elements exist because I can open the same image in another EXIF ​​editor, such as PhotoME, and they are clearly indicated there clearly as the correct identifier.

Are there levels of nesting in EXIF, and I don’t go far enough, or is there some reason why this will not work in the basic form above?

+4
source share
2 answers

Try ExifLib - there is a demo project with a source that extracts all tags from an image that you could use.

Edit: I'm going to add my answer to explain why I believe that the .Net Image class does not process all EXIF ​​tags, as we might expect. However, I am going to leave my initial link and suggestion above, as I consider this to be the best option at the end.

Ok, on Why :

, , , Windows 7 EXIF ​​ make ( > a > "" > "" ), .Net PropertyItems EXIF. , HTC One, , , . ( , -2.jpg, original-4.jpg original-8.jpg .)

img.PropertyItems.Count() 32. , ! (, , Windows 7 EXIF). , .PropertyItems Id ( ):

  • 32
  • 271 (0x010F - ) 272 (0x0110 - ).
  • 282, 283, 296, 305, 306 27
  • img.PropertyItems.Single(x => x.Id == 305).Value, SoftwareUsed ( 206, DateTime) EXIF ​​

, , .Net Image EXIF ​​ 271/272 ( , Camera Make/Model)?

ExifLib ( ) , , :

  • private byte[] GetTagBytes(...) ExifReader.cs( 655), , "Exif IDF"
  • ,
  • ASCII - .

, , .Net Image EXIF ​​ PropertyItems, .

ExifDataView (http://www.nirsoft.net/utils/exif_data_view.html) :

  • , .Net Make Model, 4 ( "HTC" + )
  • .Net, 5 ( "HTC" + null + null?)
  • ( -4.jpg) SoftwareUsed DateTime , ( ) + 1 . ( ) + 2 . , .

ExifLib / , .Net - .

.Net Image PropertyItems " " image.PropertyItems.Single(x => x.Id == tagMake).Value

: ExifLib , EXIF-, , . .NET Image, , , : -)

+2

, , , .

Sample image with EXIF ​​metadata

int tagMake = 0x010F;  // 271
int tagModel = 0x0110; // 272

Image image = Image.FromFile(@"C:\image.jpg");

byte[] make = image.PropertyItems.Single(x => x.Id == tagMake).Value;
byte[] model = image.PropertyItems.Single(x => x.Id == tagModel).Value;

var encoding = new System.Text.ASCIIEncoding();

Console.WriteLine(encoding.GetString(make));  // Returns: Canon
Console.WriteLine(encoding.GetString(model)); // Returns: Canon PowerShot S40
+1

Source: https://habr.com/ru/post/1529321/


All Articles