Image.Height Proprietà

Definizione

Ottiene l'altezza in pixel di questo oggetto Image.

C#
[System.ComponentModel.Browsable(false)]
public int Height { get; }

Valore della proprietà

Altezza in pixel di questo oggetto Image.

Attributi

Esempio

Nell'esempio di codice seguente viene illustrato come costruire una nuova bitmap da un file usando i GetPixel metodi e SetPixel per ricolorare l'immagine. Usa anche le PixelFormat proprietà e Height .

Questo esempio è progettato per essere usato con un Windows Forms che contiene rispettivamente , Labele denominato PictureBox1Label1, PictureBoxe ButtonButton1, . Incollare il codice nel modulo e associare il Button1_Click metodo all'evento del Click pulsante.

C#
Bitmap image1;

private void Button1_Click(System.Object sender, System.EventArgs e)
{

    try
    {
        // Retrieve the image.
        image1 = new Bitmap(@"C:\Documents and Settings\All Users\" 
            + @"Documents\My Music\music.bmp", true);

        int x, y;

        // Loop through the images pixels to reset color.
        for(x=0; x<image1.Width; x++)
        {
            for(y=0; y<image1.Height; y++)
            {
                Color pixelColor = image1.GetPixel(x, y);
                Color newColor = Color.FromArgb(pixelColor.R, 0, 0);
                image1.SetPixel(x, y, newColor);
            }
        }

        // Set the PictureBox to display the image.
        PictureBox1.Image = image1;

        // Display the pixel format in Label1.
        Label1.Text = "Pixel format: "+image1.PixelFormat.ToString();
    }
    catch(ArgumentException)
    {
        MessageBox.Show("There was an error." +
            "Check the path to the image file.");
    }
}

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