熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET入門教程 14.1.1 對象處理[3]

2013-11-13 11:09:16  來源: .NET編程 

    內部的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

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15275.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.