Results 1 to 2 of 2

Thread: [RESOLVED] Image resolution and DPI not the same as image itself

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    7

    Resolved [RESOLVED] Image resolution and DPI not the same as image itself

    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.
    Name:  Resolutions_not_the_same04092015.jpg
Views: 419
Size:  36.9 KBName:  Resolution_not_correct1.jpg
Views: 422
Size:  38.6 KBName:  When_openingFile.jpg
Views: 424
Size:  39.8 KBName:  Resolution_WebImageCorrect.jpg
Views: 406
Size:  36.3 KB
    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

  2. #2

    Thread Starter
    New Member
    Join Date
    May 2013
    Posts
    7

    Re: Image resolution and DPI not the same as image itself

    I see that no one could answer this one. I saved the code and created a new project. For some reason I think the project got corrupted. I ran virus scan, boot time scans and malware scans to eliminate that possibility and none were found. Once I created the new project, it was fine.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width