0

我有:1 OpenFileDialog、1 PictureBox、2 TextBox

这是我到目前为止所得到的,但我只是坚持如何让图像的宽度自动检测并将图像宽度(以像素为单位)放在 TextBox1 中,并将高度放在 TextBox2 中。

有谁知道如何做到这一点,或者我可以用它吗?

Public Class Form1
    Private sizew As Integer
    Private sizey As Integer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage

        OpenFileDialog1.CheckFileExists = True
        OpenFileDialog1.ShowReadOnly = False
        OpenFileDialog1.Filter = "All Files|*.*|Bitmap |*.bmp;*.dib|JPEG |*.jpg;*.jpeg;*.jpe;*.jfif|TIFF |*.tif;*.tiff |PNG |*.png"
        OpenFileDialog1.FilterIndex = 1
        If OpenFileDialog1.ShowDialog = DialogResult.OK Then
            PictureBox1.Image = Image.FromFile(OpenFileDialog1.FileName)
        End If
    End Sub
End Class
4

1 回答 1

1

以像素为单位的图像尺寸:

?pictureBox1.Image.Width 
526
?pictureBox1.Image.Height 
81

图片框尺寸:

?pictureBox1.ClientSize.Width 
100
?pictureBox1.ClientSize.Height
50

因此:

textBox1.Text = pictureBox1.Image.Width  
textBox2.Text = pictureBox1.Image.Height
于 2012-05-07T02:21:37.073 回答