Detect Image Size in 2 TextBox's

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
3 posts Page 1 of 1
Contributors
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Detect Image Size in 2 TextBox's
mikethedj4
What I have: 1 OpenFileDialog, 1 PictureBox, 2 TextBox's

I already have it setup so when you browse, and select a image it'll show in a picturebox. Now I'm trying to figure out how it'll automatically detect the image's width, and height, but put the height in 1 textbox, and the width in another.

Anyone know how to achieve this?


Here's the coding so far...
Code: Select all
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
Last edited by mikethedj4 on Mon May 07, 2012 2:13 am, edited 1 time in total.
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

You can do this to put the image into a variable:
Code: Select all
Dim bm as new bitmap("Image File Name Here")
Then you can use these to get the dimensions:
Code: Select all
textbox1.text = bm.width
textbox2.text = bm.height
I hope this helps :D
http://www.megaapps.tk/
User avatar
mikethedj4
VIP - Site Partner
VIP - Site Partner
Posts: 2592
Joined: Thu Mar 25, 2010 4:36 am

Thanks, but that won't work for what I'm trying to accomplish. However my question was answered on StackOverflow.
3 posts Page 1 of 1
Return to “Coding Help & Support”