EDN Admin
Well-known member
I use the following code to show images when I click on corresponding file names in a listbox. It works fine non-recursively but I need to expand it to show files recursively:
photos = System.IO.Directory.GetFiles(sp, *.jpg|*.gif|*.png|*.bmp|*.jpe|*.jpeg|*.ico|*.tif|*.tiff")
If photos.Length > 0 Then
currentPhoto = 0
DisplayPhoto()
Else
FileListBox1.Items.Clear()
End If
Public Sub DisplayPhoto()
clears picturebox1
Me.PictureBox1.Image = Nothing
Try
Img = Drawing.Image.FromFile(photos(currentPhoto))
Dim ThumbnailHeight As Integer
Dim ThumbnailWidth As Integer
If Img.Width > Me.PictureBox1.Width Then
ThumbnailWidth = Me.PictureBox1.Width
If Img.Height > Me.PictureBox1.Height Then
ThumbnailHeight = Me.PictureBox1.Height
calls the thumbnail of this image
Img = Img.GetThumbnailImage(ThumbnailWidth, ThumbnailHeight, Nothing, Nothing)
Else
if image is smaller than picturebox, it expands image to fill picture box
If Img.Width < Me.PictureBox1.Width Then
ThumbnailHeight = CInt((ThumbnailWidth / Img.Width) * Img.Height)
ThumbnailWidth = CInt((ThumbnailHeight / Img.Height) * Img.Width)
End If
End If
End If
displays resulting image in picturebox1
Me.PictureBox1.Image = Img
ImageViewer.picImage.Image = Img
Catch When Err.Number = 7
MsgBox("Encountered Non-Image File. Click to continue.", , "File Type Error")
End Try
Dim Filename As String = System.IO.Path.GetFileName(photos(currentPhoto))
Me.txtFileName.Text = Filename
ImageViewer.lblFileName.Text = Filename
End If
End Sub
The second part of this is - is there a way to show for example multi-page tiffs in a picture box? I havent been able to fund any code for that.
Thanks in advance.
View the full article
photos = System.IO.Directory.GetFiles(sp, *.jpg|*.gif|*.png|*.bmp|*.jpe|*.jpeg|*.ico|*.tif|*.tiff")
If photos.Length > 0 Then
currentPhoto = 0
DisplayPhoto()
Else
FileListBox1.Items.Clear()
End If
Public Sub DisplayPhoto()
clears picturebox1
Me.PictureBox1.Image = Nothing
Try
Img = Drawing.Image.FromFile(photos(currentPhoto))
Dim ThumbnailHeight As Integer
Dim ThumbnailWidth As Integer
If Img.Width > Me.PictureBox1.Width Then
ThumbnailWidth = Me.PictureBox1.Width
If Img.Height > Me.PictureBox1.Height Then
ThumbnailHeight = Me.PictureBox1.Height
calls the thumbnail of this image
Img = Img.GetThumbnailImage(ThumbnailWidth, ThumbnailHeight, Nothing, Nothing)
Else
if image is smaller than picturebox, it expands image to fill picture box
If Img.Width < Me.PictureBox1.Width Then
ThumbnailHeight = CInt((ThumbnailWidth / Img.Width) * Img.Height)
ThumbnailWidth = CInt((ThumbnailHeight / Img.Height) * Img.Width)
End If
End If
End If
displays resulting image in picturebox1
Me.PictureBox1.Image = Img
ImageViewer.picImage.Image = Img
Catch When Err.Number = 7
MsgBox("Encountered Non-Image File. Click to continue.", , "File Type Error")
End Try
Dim Filename As String = System.IO.Path.GetFileName(photos(currentPhoto))
Me.txtFileName.Text = Filename
ImageViewer.lblFileName.Text = Filename
End If
End Sub
The second part of this is - is there a way to show for example multi-page tiffs in a picture box? I havent been able to fund any code for that.
Thanks in advance.
View the full article