基本信息
源码名称:vb 具有预览功能的图像查看器用户控件
源码大小:0.08M
文件格式:.zip
开发语言:C#
更新时间:2019-01-18
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
Imports System.IO
Imports System.Collections
Public Class ImageViewer
' private member variables
Private mFolder As String
Private mImageList As ArrayList
Private mImagePosition As Integer
Private mPreviousImage As Image
Private mCurrentImage As Image
Private mNextImage As Image
''' <summary>
''' Default Constructor
''' </summary>
''' <remarks></remarks>
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
''' <summary>
''' Default load event handler
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub ImageViewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' do nothing
End Sub
''' <summary>
''' Open the folder browse dialog and load
''' the initial images
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
' Label the folder browser dialog
Me.folderBrowserDialog1.Description = "Select the image directory."
' disable create folder feature of folder browser
Me.folderBrowserDialog1.ShowNewFolderButton = False
' display the folder browser
Dim result As DialogResult = folderBrowserDialog1.ShowDialog()
If result = DialogResult.OK Then
' on okay, set the image folder to the
' folder browser's selected path
mFolder = folderBrowserDialog1.SelectedPath
If (Not String.IsNullOrEmpty(mFolder)) Then
txtImageDirectory.Text = mFolder
Else
' exit if the user cancels
Return
End If
' initialize the image arraylist
mImageList = New ArrayList()
' loop through the image directory
' and find all of the image files
' add the found files to the image
' list - add other image types if
' necessary
Dim Dir As New DirectoryInfo(mFolder)
Dim f As FileInfo
For Each f In Dir.GetFiles("*.*")
Select Case (f.Extension.ToUpper())
Case ".JPG"
mImageList.Add(f.FullName)
Case ".BMP"
mImageList.Add(f.FullName)
Case ".GIF"
mImageList.Add(f.FullName)
Case Else
' skip file
End Select
Next
' set the starting position to 0
' and call the set images method
' to load the pictures
mImagePosition = 0
SetImages()
End If
End Sub
''' <summary>
''' This function is used to set the previous,
''' current, and next images into the
''' correct picture boxes
''' </summary>
''' <remarks></remarks>
Private Sub SetImages()
' clear any existing images
' memory will be an issue if
' cycling through a large
' number of images
mPreviousImage = Nothing
mNextImage = Nothing
mCurrentImage = Nothing
' set the previous image
If mImagePosition > 0 Then
Try
' set delegate
Dim prevCallback As Image.GetThumbnailImageAbort = _
New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
' get the previous image
Dim prevBmp As _
New Bitmap(mImageList(mImagePosition - 1).ToString())
' thumbnail the image to the size
' of the picture box
mPreviousImage = _
prevBmp.GetThumbnailImage(160, 100, _
prevCallback, IntPtr.Zero)
' set the picture box image
picPreviousImage.Image = mPreviousImage
' clear everything out
prevBmp = Nothing
prevCallback = Nothing
mPreviousImage = Nothing
Catch
'stall if it hangs, the user can retry
End Try
Else
' at the limit clear the
' image
picPreviousImage.Image = Nothing
End If
' set current image
If mImagePosition < mImageList.Count Then
Try
' set delegate
Dim currentCallback = _
New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
' get the current image
Dim currentBmp As _
New Bitmap(mImageList(mImagePosition).ToString())
' thumbnail the image to the size
' of the picture box
mCurrentImage = _
currentBmp.GetThumbnailImage(320, 200, currentCallback, IntPtr.Zero)
' set the picture box image
picCurrentImage.Image = mCurrentImage
' clear everything out
currentBmp = Nothing
mCurrentImage = Nothing
currentCallback = Nothing
Catch
'stall if it hangs, the user can retry
End Try
End If
' set next image
If mImagePosition < mImageList.Count - 1 Then
Try
' set delegate
Dim nextCallback As _
New Image.GetThumbnailImageAbort(AddressOf ThumbnailCallback)
' get the next image
Dim nextBmp As _
New Bitmap(mImageList(mImagePosition 1).ToString())
' thumbnail the image to the size
' of the picture box
mNextImage = _
nextBmp.GetThumbnailImage(160, 100, nextCallback, IntPtr.Zero)
' set the picture box image
picNextImage.Image = mNextImage
' clear everything out
nextBmp = Nothing
nextCallback = Nothing
mNextImage = Nothing
Catch
'stall if it hangs, the user can retry
End Try
Else
' at the limit clear the
' image
picNextImage.Image = Nothing
End If
' call for garbage collection
GC.Collect()
End Sub
''' <summary>
''' Thumbnail image abort target
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function ThumbnailCallback() As Boolean
Return False
End Function
''' <summary>
''' Set the image position and reset all
''' of the images when the previous image
''' button is clicked
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnPreviousImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPreviousImage.Click
If (mImagePosition >= 0 And Not picPreviousImage.Image Is Nothing) Then
mImagePosition -= 1
SetImages()
End If
End Sub
''' <summary>
''' Set the image position and reset all
''' of the images when the next image
''' button is clicked
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnNextImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextImage.Click
If (mImagePosition <= (mImageList.Count - 2)) Then
mImagePosition = 1
SetImages()
End If
End Sub
''' <summary>
''' Open the current image using the default
''' program per the user's file associations
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub btnOpenImage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpenImage.Click
System.Diagnostics.Process.Start(mImageList(mImagePosition).ToString())
End Sub
End Class