内部的Try/Catch块则包围在targetImage外部根据SourceImage使用利用新高度和宽度的GetThumbnailImage生成TargetImage这可以创建基于新尺寸的新图像一旦生成targetlmage则作为GIF图像被保存为文件
通过调用Dispose方法每个Try/Catch的Finally块在处理Image对象前检查该对象 是否存在
使用Using语句进行处理
Using语句可简化前面的代码具体如下所示
Public Shared Sub GenerateThumbnail(ByVal SourceImagePath As String ByVal TargetImagePath As String)
Dim newHeight As Short
Dim newWidth As Short
Using sourceImage As Image = ImageFromFile(SourceImagePath)
newHeight = CShort(sourceImageHeight * )
newWidth = CShort(sourceImageWidth * )
Dim cb As New ImageGetThumbnailImageAbort(AddressOf ThumbnailCallback)
Using targetImage As Image = sourceImageGetThumbnailImage(newWidth newHeight cb IntPtrZero)
targetImageSave(TargetImagePath ImagingImageFormatGif)
End Using
End Using
End Sub
[] [] [] []