我正在使用 vb.net 编写,并且使用的是 Visual Studio 2010 Professional
好的,我将展示我的代码,然后解释我需要什么帮助。
Imports System.IO.File
Imports System.IO.Directory
Imports System.IO
Public Class ImageSelection
Private Sub ImageSelectionbtn_Click(sender As System.Object, e As System.EventArgs) Handles ImageSelectionbtn.Click
With OpenFileDialog1
.Filter = _
"Image File (*.jpg)|*.jpg|Image File (*.jpeg)|*.jpeg|Image File (*.bmp)|*.bmp|Image File (*.gif)|*.gif"
.InitialDirectory = System.Environment.SpecialFolder.MyPictures
.Title = "Select a picture to open"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
''''Here is where i need help''''
Dim MyImage = OpenFileDialog1.FileName
Dim MyImageWidth
Dim MyImageHeight
'''''''''''''''''''''''''''''''''
With MyPicture 'MyPicture form
.Width = MyImageWidth
.Height = MyImageHeight
.PictureBox1.Image = Nothing
MyPicture.Show()
End With
End If
End With
End Sub
End Class
好的,所以我要做的是,当用户单击该按钮时,它会弹出一个打开文件对话框,该对话框被过滤为仅允许 .jpg
.jpeg
.bmp
和 .gif
现在,当他们选择图片时,我需要一种方法来从所选图像中提取少量信息。
我需要图像高度和图像宽度,以便我可以将另一个表单(带有表单停靠图像框)设置为该图像的大小。
我还需要帮助将第二种形式中的 picturebox
设置为他们选择的图像。
任何帮助将不胜感激。
最佳答案
With OpenFileDialog1
.Filter = _
"Image File (*.jpg)|*.jpg|Image File (*.jpeg)|*.jpeg|Image File (*.bmp)|*.bmp|Image File (*.gif)|*.gif"
.InitialDirectory = System.Environment.SpecialFolder.MyPictures
.Title = "Select a picture to open"
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
''''Here is where i need help''''
Dim MyImage = OpenFileDialog1.FileName
Dim image As Image = System.Drawing.Bitmap.FromFile(MyImage) 'Convert to Image from the selected file
Dim MyImageWidth As Integer = image.Width 'Get The Width
Dim MyImageHeight As Integer = image.Height 'Get The Height
'''''''''''''''''''''''''''''''''
With MyPicture 'MyPicture form
.Width = MyImageWidth
.Height = MyImageHeight
.PictureBox1.Image = image
MyPicture.Show()
End With
End If
End With
关于vb.net - 获取所选图像的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15389037/