0

What I have: 1 OpenFileDialog, 1 PictureBox, 2 TextBox's

This is what I got so far, but I'm just stuck on how to have the width of the image automatically detect and put the images width in pixels in TextBox1, and the height in TextBox2.

Does anyone know how to do this, or can me with it?

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
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
Michael Schwartz
  • 8,153
  • 14
  • 81
  • 144

1 Answers1

1

Image dimensions in Pixels:

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

PictureBox Dimensions:

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

Hence:

textBox1.Text = pictureBox1.Image.Width  
textBox2.Text = pictureBox1.Image.Height
Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321