vb.net - 获取所选图像的属性

标签 vb.net winforms openfiledialog

我正在使用 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/

相关文章:

vb.net - 删除字符串中的最后 4 个字符?

c# - 从其他类更新 UI 的最佳方式?

java - FileServlet(BalusC 的解决方案)在 IE 中不显示保存对话框

c++ - 使用 OpenCV Mat 作为数组 : VB vs C++

c# - 比较地址的两个字符串时如何获得百分比准确度匹配?

vb.net - 戴帽子的名字 suffle vb.net

c# - 如何使用 C# 连接到 Winform 应用程序中的 .sdf 文件?

c# - Winform Datagridview 不显示数据

c++ - WT 保存文件对话框窗口?

c# - OpenFileIDialog C# 中作为文件名的 URL