Image.PropertyItems Proprietà

Definizione

Ottiene tutti gli elementi di proprietà (porzioni di metadati) archiviati in questo oggetto Image.

C#
[System.ComponentModel.Browsable(false)]
public System.Drawing.Imaging.PropertyItem[] PropertyItems { get; }

Valore della proprietà

Matrice di oggetti PropertyItem, uno per ciascun elemento di proprietà archiviato nell'immagine.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come leggere e visualizzare i metadati in un file di immagine usando la System.Drawing.Imaging.PropertyItem classe e la PropertyItems proprietà .

Questo esempio è progettato per essere utilizzato un Windows Form che importa lo System.Drawing.Imaging spazio dei nomi. Incollare il codice nel modulo e modificare il percorso in modo fakePhoto.jpg che punti a un file di immagine nel sistema. Chiamare il ExtractMetaData metodo quando si gestisce l'evento del Paint modulo, passando e come PaintEventArgs.

C#
private void ExtractMetaData(PaintEventArgs e)
{
    try
    {
        // Create an Image object. 
        Image theImage = new Bitmap("c:\\fakePhoto.jpg");

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

        // Set up the display.
        Font font1 = new Font("Arial", 10);
        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(), font1, blackBrush, X, Y);
            Y += font1.Height;

            e.Graphics.DrawString("   ID: 0x" + 
                propItem.Id.ToString("x"), font1, blackBrush, X, Y);
            Y += font1.Height;

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

            e.Graphics.DrawString("   length: " + 
                propItem.Len.ToString() + 
                " bytes", font1, blackBrush, X, Y);
            Y += font1.Height;
            count += 1;
        }
        font1.Dispose();
    }
    catch(Exception)
    {
        MessageBox.Show("There was an error." + 
            "Make sure the path to the image file is valid.");
    }
}

Commenti

Se l'immagine non contiene elementi di proprietà o se il formato dell'immagine non supporta gli elementi della proprietà, PropertyItems restituisce una matrice vuota, ovvero una matrice di lunghezza zero.

Si applica a

Prodotto Versioni
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Vedi anche