Results 1 to 5 of 5

Thread: [2008] Find the size of the image

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    [2008] Find the size of the image

    how can i find the size of an image ?
    Im using this code, and I want to check the size of the image before adding it to the list view, if the image size is 96x96 then i add it, if not i skip it.
    Code:
            For Each fname As String In files
    
                Dim bmp As Bitmap
                Dim streamreader As New System.IO.StreamReader(fname)
                Try
                    bmp = New Bitmap(Image.FromStream(streamreader.BaseStream))
                    Me.ImageList1.Images.Add("", bmp)
                    ListView1.Items.Add("", i)
                Catch ex As Exception
                Finally
                    streamreader.Close()
                End Try
                i = i + 1
            Next
    if u want to know why i use this code, http://www.vbforums.com/showthread.php?t=505807

    ie: how can i find the size of an image in an imagelist?

  2. #2
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: [2008] Find the size of the image

    vb.net Code:
    1. For Each fname As String In files
    2.  Dim bmp As Bitmap
    3.  Dim file_reader As New System.IO.FileStream(fname, IO.FileMode.Open)
    4.  Dim binary_reader As New System.IO.BinaryReader(file_reader)
    5.   Try
    6.    bmp = New Bitmap(Image.FromStream(binary_reader.BaseStream))
    7.    If bmp.Height = 96 And bmp.Width = 96 Then
    8.     Me.ImageList1.Images.Add("", bmp)
    9.     ListView1.Items.Add(fname, "", i)
    10.    End If
    11.   Catch ex As Exception
    12.   Finally
    13.    file_reader.Close()
    14.    binary_reader.Close()
    15.   End Try
    16.  i = i + 1
    17. Next
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Re: [2008] Find the size of the image

    k thx
    this code works, but there is an error in the original code i just discovered

    Code:
            For Each t As ListViewItem In Me.ListView1.Items
                If t.Selected = True Then MessageBox.Show(t.Name)
            Next
    this will not always work correctly, i mean, for the first few images it will give the right path.
    but then, for most other images, it will give a different path, (a path for another image... ) the names are mixed up for some reason :S

  4. #4
    Fanatic Member TokersBall_CDXX's Avatar
    Join Date
    Mar 2003
    Location
    America
    Posts
    571

    Re: [2008] Find the size of the image

    the names appear to match to me...
    Build your own personalized flash based chat room for your webpage for FREE! http://www.4computerheaven.com

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    167

    Re: [2008] Find the size of the image

    all of them?
    this is weird.. i just followed them.. and find out that at the nineth image the error start, the nineth image's path is found when clicking on the image before it (eight)... the tenth image's path is found when clicking on the image nine...

    are u sure u have no problem?

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