Files
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

4.4 KiB

title, desription, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title desription ms.date dev_langs helpviewer_keywords ms.assetid
How to: Read Image Metadata Learn how to read the Windows Forms PropertyItems property of an Image object to retrieve all the metadata from a file. 03/30/2017
csharp
vb
metadata [Windows Forms], property item
metadata [Windows Forms], reading image
72ec0b31-0be7-444a-9575-1dbcb864e0be

How to: Read Image Metadata

Some image files contain metadata that you can read to determine features of the image. For example, a digital photograph might contain metadata that you can read to determine the make and model of the camera used to capture the image. With GDI+, you can read existing metadata, and you can also write new metadata to image files.

GDI+ stores an individual piece of metadata in a xref:System.Drawing.Imaging.PropertyItem object. You can read the xref:System.Drawing.Image.PropertyItems%2A property of an xref:System.Drawing.Image object to retrieve all the metadata from a file. The xref:System.Drawing.Image.PropertyItems%2A property returns an array of xref:System.Drawing.Imaging.PropertyItem objects.

A xref:System.Drawing.Imaging.PropertyItem object has the following four properties: Id, Value, Len, and Type.

Id

A tag that identifies the metadata item. Some values that can be assigned to xref:System.Drawing.Imaging.PropertyItem.Id%2A are shown in the following table:

Hexadecimal value Description
0x0320

0x010F

0x0110

0x9003

0x829A

0x5090

0x5091
Image title

Equipment manufacturer

Equipment model

ExifDTOriginal

Exif exposure time

Luminance table

Chrominance table

Value

An array of values. The format of the values is determined by the xref:System.Drawing.Imaging.PropertyItem.Type%2A property.

Len

The length (in bytes) of the array of values pointed to by the xref:System.Drawing.Imaging.PropertyItem.Value%2A property.

Type

The data type of the values in the array pointed to by the Value property. The formats indicated by the Type property values are shown in the following table:

Numeric value Description
1 A Byte
2 An array of Byte objects encoded as ASCII
3 A 16-bit integer
4 A 32-bit integer
5 An array of two Byte objects that represent a rational number
6 Not used
7 Undefined
8 Not used
9 SLong
10 SRational

Example

The following code example reads and displays the seven pieces of metadata in the file FakePhoto.jpg. The second (index 1) property item in the list has xref:System.Drawing.Imaging.PropertyItem.Id%2A 0x010F (equipment manufacturer) and xref:System.Drawing.Imaging.PropertyItem.Type%2A 2 (ASCII-encoded byte array). The code example displays the value of that property item.

[!code-csharpSystem.Drawing.WorkingWithImages#51] [!code-vbSystem.Drawing.WorkingWithImages#51]

The code produces output similar to the following:

 Property Item 0
  
 id: 0x320
  
 type: 2

 length: 16 bytes
  
 Property Item 1
  
 id: 0x10f
  
 type: 2
  
 length: 17 bytes
  
 Property Item 2
  
 id: 0x110
  
 type: 2
  
 length: 7 bytes
  
 Property Item 3
  
 id: 0x9003
  
 type: 2
  
 length: 20 bytes
  
 Property Item 4
  
 id: 0x829a
  
 type: 5
  
 length: 8 bytes
  
 Property Item 5
  
 id: 0x5090
  
 type: 3
  
 length: 128 bytes
  
 Property Item 6
  
 id: 0x5091
  
 type: 3
  
 length: 128 bytes
  
 The equipment make is Northwind Camera.

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires xref:System.Windows.Forms.PaintEventArgs e, which is a parameter of the xref:System.Windows.Forms.Control.Paint event handler. Handle the form's xref:System.Windows.Forms.Control.Paint event and paste this code into the paint event handler. You must replace FakePhoto.jpg with an image name and path valid on your system and import the System.Drawing.Imaging namespace.

See also