3 Replies - 15318 Views - Last Post: 11 September 2008 - 08:08 AM Rate Topic: -----

#1 ashbyenterprizes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 05-September 08

image width and height

Posted 10 September 2008 - 11:36 PM

Private Sub imgBrowseBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
		Dim open As New OpenFileDialog
		open.Filter = "Image Files (*.gif;*.jpg;*.png)|*.gif;*.jpg;*.png"
		open.Title = "Select File"
		open.CheckFileExists = True
		open.ShowDialog(Me)
		Try
			imgTexturl.Text = "file:///" & open.FileName
			imgPrev.ImageLocation = open.FileName
			imgTextWidth.Text = imgPrev.Image.Width
			imgTextHeight.Text = imgPrev.Image.Height
		Catch ex As Exception
			' Do nothing on Exception
		End Try
	End Sub 


2 questions:

1. Is there a way to get open.FileName to return a relative path instead of absolute so I can leave off the file:///.

2. I am trying to get the image width and height into 2 text boxes. from imgPrev. What am I doing wrong? By the way imgPrev is a picture box.

Thanks again.

Is This A Good Question/Topic? 0
  • +

Replies To: image width and height

#2 WayneSpangler  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 106
  • Joined: 22-March 08

Re: image width and height

Posted 11 September 2008 - 12:33 AM

Use a bitmap.
Public Class Form1
	Dim bmp As Bitmap

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim open As New OpenFileDialog
		open.Filter = "Image Files (*.gif;*.jpg;*.png)|*.gif;*.jpg;*.png"
		open.Title = "Select File"
		open.CheckFileExists = True
		If open.ShowDialog = Windows.Forms.DialogResult.OK Then
			'two ways to get the file size
			bmp = New Bitmap(open.FileName)
			MessageBox.Show("Width = " & bmp.Width.ToString & vbNewLine & "Height = " & bmp.Height.ToString)
			Dim siz As SizeF = bmp.Size
			MessageBox.Show("Width = " & siz.Width.ToString & vbNewLine & "Height = " & siz.Height.ToString)
		End If
		' you can't get relative path but you can get just the filename
		MessageBox.Show(open.SafeFileName)

	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#3 allensmith  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 11
  • Joined: 04-June 08

Re: image width and height

Posted 11 September 2008 - 01:13 AM

Hello,

You can have the Height and width in the given manner as well.

			Dim img As Image = Image.FromFile(open.FileName)
			TextBox3.Text = "file:///" & open.FileName
			ImagePrev.Image = img
			TextBox1.Text = img.Height
			TextBox2.Text = img.Width



But you do not have the option to get relative path. Though you can find some articles online
to generate Relative Path. For example:

http://blogs.artinso...ative-path.aspx

I hope this will help.

Regards,
Allen
Was This Post Helpful? 1
  • +
  • -

#4 ashbyenterprizes  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 05-September 08

Re: image width and height

Posted 11 September 2008 - 08:08 AM

Thanks everyone,
you really helped although since I like to use the shortest way of doing things I used AllenSmiths suggestion.

Thanks again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1