CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Images loading

  1. #1
    Join Date
    May 2005
    Posts
    18

    Images loading

    Hi All,

    I am dealing with images first time.

    I have to load images from two folders say folder1 and folder2 and view it in picturebox1 and picturebox2, Then on button click event of next and previous I have to view images from both the pictureboxes as i have to do visual compariosion of the images.

    Can anyone please provide me examples for the same or any references for the same. Also supports for max images(bmp, png, svg, jpeg, jpg.....)

    Thanks,
    Shailesh

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Images loading

    To load a picture into a picturebox you could use:
    Code:
    Dim NewImage As Image = Image.FromFile("Loacation and name of picture file")
    PictureBox1.Image = NewImage
    
    'OR
    PictureBox1.Image = Image.FromFile("Loacation and name of picture file")
    I'm not sure I understand the Comparison part
    What do you want to compare ¿

  3. #3
    Join Date
    May 2005
    Posts
    18

    Re: Images loading

    Hi,

    About comparision.

    I have to compare size, height, width and variation.
    Also I have to display folder1 image properties on status bar.

    Thanks
    Shailesh

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Images loading

    You can use:
    Code:
     Private Function loadImage(ByVal iFileName As String) As Boolean
            Try
                Dim pImgImage As Image
                pImgImage = Image.FromFile(iFileName)
                cIntImageHeight = pImgImage.Height
                cIntImageWidth = pImgImage.Width
                PictureBox1.Image = pImgImage
                Return True
            Catch
                Return False
            End Try
        End Function
    'The call in button click
    loadImage("path and name of image file")
    To obtain Height and width info of the picture
    Last edited by HanneSThEGreaT; October 5th, 2005 at 02:17 AM.

  5. #5
    Join Date
    May 2005
    Posts
    18

    Re: Images loading

    Hi,

    With the given code I have tried this:

    Private Sub btnInputSource_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInputSource.Click
    openFileDialog1.Multiselect = True
    If openFileDialog1.ShowDialog() = DialogResult.OK Then
    If Not (openFileDialog1.FileNames Is Nothing) Then
    Dim i As Integer
    For i = 0 To openFileDialog1.FileNames.Length - 1
    loadImage(OpenFileDialog1.FileNames(i))
    Next i
    Else
    loadImage(OpenFileDialog1.FileName)
    End If
    End If
    End Sub

    Private Function loadImage(ByVal iFileName As String) As Boolean
    Dim cIntImageHeight As Integer
    Dim cIntImageWidth As Integer
    Try
    Dim pImgImage As Image
    pImgImage = Image.FromFile(iFileName)
    cIntImageHeight = pImgImage.Height
    cIntImageWidth = pImgImage.Width
    PictureBox1.Image = pImgImage
    Return True
    Catch
    Return False
    End Try
    'The call in button click
    loadImage("iFileName")
    End Function

    The Above code displays the image in PictureBox1. Here I have loaded multiple images how will i display them on button next.

    Thanks,
    Shailesh

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

Featured