Image.Height 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取此 Image 的高度(以像素为单位)。
public:
property int Height { int get(); };
[System.ComponentModel.Browsable(false)]
public int Height { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Height : int
Public ReadOnly Property Height As Integer
属性值
此 Image 的高度(以像素为单位)。
- 属性
示例
下面的代码示例演示如何使用 GetPixel 和 SetPixel 方法从文件构造新位图,以重新着色图像。 它还使用 PixelFormat 和 Height 属性。
此示例旨在与分别包含 Label、PictureBox、 和 Button 、PictureBox1
Label1
、 和 Button1
的 Windows 窗体一起使用。 将代码粘贴到窗体中,并将 Button1_Click
方法与按钮的事件 Click 相关联。
private:
Bitmap^ image1;
void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
try
{
// Retrieve the image.
image1 = gcnew Bitmap( "C:\\Documents and Settings\\All Users\\"
"Documents\\My Music\\music.bmp",true );
int x;
int 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 = String::Format( "Pixel format: {0}", image1->PixelFormat );
}
catch ( ArgumentException^ )
{
MessageBox::Show( "There was an error."
"Check the path to the image file." );
}
}
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.");
}
}
Dim image1 As Bitmap
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Try
' Retrieve the image.
image1 = New Bitmap( _
"C:\Documents and Settings\All Users\Documents\My Music\music.bmp", _
True)
Dim x, y As Integer
' Loop through the images pixels to reset color.
For x = 0 To image1.Width - 1
For y = 0 To image1.Height - 1
Dim pixelColor As Color = image1.GetPixel(x, y)
Dim newColor As Color = _
Color.FromArgb(pixelColor.R, 0, 0)
image1.SetPixel(x, y, newColor)
Next
Next
' Set the PictureBox to display the image.
PictureBox1.Image = image1
' Display the pixel format in Label1.
Label1.Text = "Pixel format: " + image1.PixelFormat.ToString()
Catch ex As ArgumentException
MessageBox.Show("There was an error." _
& "Check the path to the image file.")
End Try
End Sub