일부 이미지 파일에는 이미지의 특성을 확인하는 데 사용할 수 있는 메타데이터가 있습니다. 예를 들어, 디지털 사진에 포함된 메타데이터를 분석하면 사진 촬영에 사용한 카메라의 제조업체와 모델을 알 수 있습니다. GDI+에서는 기존 메타데이터를 읽을 수 있을 뿐 아니라 이미지 파일에 새 메타데이터를 쓸 수도 있습니다.

GDI+에서는 개별 메타데이터를 PropertyItem 개체에 저장합니다. Image 개체의 PropertyItems 속성을 읽어 파일에 있는 모든 메타데이터를 검색할 수 있습니다. PropertyItems 속성은 PropertyItem 개체 배열을 반환합니다.

PropertyItem 개체에는 Id, Value, LenType이라는 네 가지 속성이 있습니다.

Id

메타데이터 항목을 식별하는 태그입니다. Id에 할당할 수 있는 값 중 일부가 다음 표에 나와 있습니다.

16진수 값
설명

0x0320

0x010F

0x0110

0x9003

0x829A

0x5090

0x5091

이미지 타이틀

장비 제조업체

장비 모델

ExifDTOriginal

Exif 노출 시간

광도 테이블

색소 테이블

Value

값 배열입니다. 값의 형식은 Type 속성에 따라 결정됩니다.

Len

Value 속성이 가리키는 값 배열의 바이트 단위 길이입니다.

Type

Value 속성이 가리키는 배열에 있는 값의 데이터 형식입니다. Type 속성 값이 나타내는 형식이 다음 표에 나와 있습니다.

숫자 값
설명

1

Byte입니다.

2

ASCII로 인코딩된 Byte 개체의 배열입니다.

3

16비트 정수입니다.

4

32비트 정수입니다.

5

유리수를 나타내는 Byte 개체 두 개로 이루어진 배열입니다.

6

사용되지 않습니다.

7

정의되어 있지 않습니다.

8

사용되지 않습니다.

9

SLong

10

SRational

예제

<?XML:NAMESPACE PREFIX = [default] http://ddue.schemas.microsoft.com/authoring/2003/5 NS = "http://ddue.schemas.microsoft.com/authoring/2003/5" />

설명

다음 코드 예제에서는 FakePhoto.jpg 파일에 있는 일곱 가지 메타데이터를 읽고 화면에 표시합니다. 목록에서 두 번째(인덱스 1)

속성 항목의 Id는 0x010F(장비 제조업체)이고 Type은 2(ASCII로 인코딩된 바이트 배열)입니다. 코드 예제에서는 해당 속성

항목의 값을 표시합니다.

코드를 실행하면 아래와 비슷한 결과가 나타납니다.

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.

 

C#

// Create an Image object. 
Image image = new Bitmap("c:\FakePhoto.jpg");

// Get the PropertyItems property from image.
PropertyItem[] propItems = image.PropertyItems; 

// Set up the display.
Font font = new Font("Arial", 12);
SolidBrush blackBrush = new SolidBrush(Color.Black);
int X = 0;
int Y = 0;

// For each PropertyItem in the array, display the ID, type, and 
// length.
int count = 0;
foreach (PropertyItem propItem in propItems)
{
   e.Graphics.DrawString(
   "Property Item " + count.ToString(),
   font,
   blackBrush,
   X, Y);
   
   Y += font.Height;

   e.Graphics.DrawString(
      "   iD: 0x" + propItem.Id.ToString("x"),
      font,
      blackBrush,
      X, Y);

   Y += font.Height;

   e.Graphics.DrawString(
      "   type: " + propItem.Type.ToString(),
      font,
      blackBrush,
      X, Y);

   Y += font.Height;

   e.Graphics.DrawString(
      "   length: " + propItem.Len.ToString() + " bytes",
      font,
      blackBrush,
      X, Y);

   Y += font.Height;

   count++;
}
// Convert the value of the second property to a string, and display 
// it.
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string manufacturer = encoding.GetString(propItems[1].Value);

e.Graphics.DrawString(
   "The equipment make is " + manufacturer + ".",
   font,
   blackBrush,
   X, Y);

코드 컴파일

앞의 예제는 Windows Forms에서 사용해야 하며 Paint 이벤트 처리기의 매개 변수인 PaintEventArgs e를 필요로 합니다. FakePhoto.jpg를 시스템에서 사용할 수 있는 이미지 이름 및 경로로 바꾸십시오.

참고 항목

기타 리소스
이미지, 비트맵 및 메타파일
이미지, 비트맵 및 메타파일 사용

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.ko/dv_fxmclignrl/html/72ec0b31-0be7-444a-9575-1dbcb864e0be.htm

+ Recent posts