2010-05-06 111 views
2

我在Resources中有圖像,並且想要獲取它們的ID。 我從MSDN中找不到以下代碼非常有幫助。在Windows窗體中獲取屬性ID

它是如何得到數字20624和20625?

如果我有用Properties.Resources.Image1訪問的圖像,如何以編程方式獲取其ID?

private void DemonstratePropertyItem(PaintEventArgs e) 
{ 

    // Create two images. 
    Image image1 = Image.FromFile("c:\\FakePhoto1.jpg"); 
    Image image2 = Image.FromFile("c:\\FakePhoto2.jpg"); 

    // Get a PropertyItem from image1. 
    PropertyItem propItem = image1.GetPropertyItem(20624); 

    // Change the ID of the PropertyItem. 
    propItem.Id = 20625; 

    // Set the PropertyItem for image2. 
    image2.SetPropertyItem(propItem); 

    // Draw the image. 
    e.Graphics.DrawImage(image2, 20.0F, 20.0F); 
} 

回答

0

MSDN提供了一個list of propertyitem ids in hexdecimal format及其相應的標籤。

在你的榜樣,20624(0x5090)是PropertyTagLuminanceTable和20625(0x5091)是PropertyTagChrominanceTable

編輯: 剛一說明,這些ID都沒有訪問圖像本身,而是有關的元數據圖像。

+0

我完全誤解了propertyitem id的用途。我認爲ID標識圖像,我可以使用int propId檢索它們。 謝謝。 – zaidwaqi 2010-05-06 07:07:04