打開使用Image.FromFile
方法
Image image = Image.FromFile(openFileDialog1.FileName);
把圖像您image
在pictureBox1
pictureBox1.Image = image;
你需要的是System.Drawing.Image
類。圖像的大小在image.Size
屬性中。但是,如果你想獲得Width
和Height
分開,你可以使用image.Width
和image.Height
分別
然後你的其他TextBox
(假設名字是textBox2
)你可以簡單地分配Text
屬性就是這樣,
textBox2.Text = "Width: " + image.Width.ToString() + ", Height: " + image.Height.ToString();
完整代碼:
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
Image image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = image; //simply put the image here!
textBox2.Text = "Width: " + image.Width.ToString() + ", Height: " + image.Height.ToString();
}
}
來源
2015-12-27 17:19:26
Ian
Thanks!這工作:D – Remi