I am hoping one of you can help me out here. Yesterday this was working fine but today something strange is going on.
If I get a URL image and display it in the program the image informations is correct. But if I open an image from my hard disk the image information is not correct.
I have tried clearing the clipboard memory.
I have tried restarting Visual Studio.
I have restarted the computer.
This morning I did add some code to a function and thought that was the problem, so I commented (') those statements, but that had no effect either.
I am puzzled? Any thoughts?
This is my code for opening files from hard disk:
Private Sub ButOpen_Click(sender As System.Object, e As System.EventArgs) Handles ButOpen.Click
' open from file in either picbox
Dim picsave = OpenFileDialog1.FileName
Dim msgRslt As MsgBoxResult = MsgBox("Would you like the image in box one on the right?.", MsgBoxStyle.YesNoCancel)
If msgRslt = MsgBoxResult.Yes Then
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName > "" Then
'OpenFileDialog1.Filter = "JPG Image(*.Jpg)|BMP Image(*.bmp) |*.bmp" '|PNG Images (*.png)|All Files (*.*) |*.*"
PictureBox1.ImageLocation = OpenFileDialog1.FileName
End If
ElseIf msgRslt = MsgBoxResult.No Then
OpenFileDialog1.ShowDialog()
If OpenFileDialog1.FileName > "" Then
'OpenFileDialog1.Filter = "JPG Image(*.Jpg)|BMP Image(*.bmp) |*.bmp" '|PNG Images (*.png)|All Files (*.*) |*.*"
PictureBox2.ImageLocation = OpenFileDialog1.FileName
End If
End If
' Set varibles to show image information DPI and Hor & Vert Resolution
Dim image As Image = System.Drawing.Image.FromFile(picsave) '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
Dim MyImageHDPI As Integer = image.HorizontalResolution
Dim MyImageVDPI As Integer = image.VerticalResolution
' Show image information
TextImageHeight.Text = image.Height
TextImageWidth.Text = image.Width
TextHorzDPI.Text = image.HorizontalResolution
TextVetDPI.Text = image.VerticalResolution
End Sub
The Code to view URL image:
Private Sub ButLoadWebImage_Click(sender As System.Object, e As System.EventArgs) Handles ButLoadWebImage.Click
Try
' Load URL image to memory from text box string
PictureBox1.Image = New System.Drawing.Bitmap(New IO.MemoryStream(New System.Net.WebClient().DownloadData(TextBox1.Text)))
' save to clipboard
Clipboard.SetDataObject(PictureBox1.Image, True)
' show image information
TextImageHeight.Text = PictureBox1.Image.Height
TextImageWidth.Text = PictureBox1.Image.Width
Dim dpiX As Single = PictureBox1.Image.HorizontalResolution
Dim dpiY As Single = PictureBox1.Image.VerticalResolution
TextHorzDPI.Text = dpiX
TextVetDPI.Text = dpiY
TextBox1.Text = ""
' Images from the Web have to saved
PictureBox1.Image.Save(picsave1)
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub




Reply With Quote
