|
-
Jan 24th, 2008, 01:33 PM
#1
Thread Starter
Addicted Member
[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?
-
Jan 24th, 2008, 02:40 PM
#2
Fanatic Member
Re: [2008] Find the size of the image
vb.net Code:
For Each fname As String In files
Dim bmp As Bitmap
Dim file_reader As New System.IO.FileStream(fname, IO.FileMode.Open)
Dim binary_reader As New System.IO.BinaryReader(file_reader)
Try
bmp = New Bitmap(Image.FromStream(binary_reader.BaseStream))
If bmp.Height = 96 And bmp.Width = 96 Then
Me.ImageList1.Images.Add("", bmp)
ListView1.Items.Add(fname, "", i)
End If
Catch ex As Exception
Finally
file_reader.Close()
binary_reader.Close()
End Try
i = i + 1
Next
-
Jan 24th, 2008, 02:51 PM
#3
Thread Starter
Addicted Member
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
-
Jan 24th, 2008, 02:57 PM
#4
Fanatic Member
Re: [2008] Find the size of the image
the names appear to match to me...
-
Jan 24th, 2008, 03:10 PM
#5
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|