โดย tohkai_php » 20/08/2012 10:32 am
โค้ด: เลือกทั้งหมด
// 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);
จะได้
โค้ด: เลือกทั้งหมด
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.
แล้วต้องไปแปลง ASCII อีกทีนะครับ
[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);
[/code]
จะได้
[code]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]
แล้วต้องไปแปลง ASCII อีกทีนะครับ