Visual Basic检测2个TextBox中的图像大小

时间:2012-05-07 01:26:36

标签: vb.net image detect image-size

我拥有的东西: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

1 个答案:

答案 0 :(得分:1)

像素中的图像尺寸:

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

PictureBox尺寸:

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

因此:

textBox1.Text = pictureBox1.Image.Width  
textBox2.Text = pictureBox1.Image.Height