Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
CSharp_Graphics.doc
Скачиваний:
20
Добавлен:
16.11.2019
Размер:
3.1 Mб
Скачать

Пример Описание

В следующем примере кода осуществляется считывание и отображение семи блоков метаданных из файла FakePhoto.jpg. Второе свойство в списке (индекс 1) имеет значение Id 0x010F (производитель оборудование) и Type 2 (массив объектов byte в кодировке ASCII). В примере кода отображается значение данного свойства.

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.

Результат выполнения этого кода будет выглядеть примерно следующим образом:

--------

Code

// 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);

Compiling the Code

The preceding example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. Replace FakePhoto.jpg with an image name and path valid on your system.

Код

-------------