ASP.NET创建动态缩略图的方法
本文实例讲述了ASP.NET创建动态缩略图的方法。分享给大家供大家参考。具体分析如下:
提示:
1.导入System.IO
2.创建类Class"CreateThumbnails"
oranyclassandplacefollowingfunctioninsidethatclass
Youneedonefunctiontoresponsecallbacktomainfunction
FunctionImageAbortDummyCallback()AsBoolean
ReturnFalse
EndFunction
具体代码如下:
FunctionCreateJPEGThumbnail(ByValinSourceFileAsString,ByValinDestinationFileAsString,ByValThumbWidthAsInteger,ByValThumbHeightAsInteger)AsBoolean DimimageFileAsSystem.Drawing.Image DimoutputFstreamAsNewFileStream(inSourceFile,FileMode.Open,FileAccess.Read) 'ExposesaSystem.IO.Streamaroundafile,supportingbothsynchronousandasynchronousreadandwriteoperations. DimImageAbortCallBackAsSystem.Drawing.Image.GetThumbnailImageAbort 'ThismethodreturnstrueifitdecidesthattheSystem.Drawing.Image.GetThumbnailImagemethodshouldprematurelystopexecution;otherwise,itreturnsfalse. imageFile=System.Drawing.Image.FromStream(outputFstream) ImageAbortCallBack=NewSystem.Drawing.Image.GetThumbnailImageAbort(AddressOfImageAbortDummyCallback) imageFile=imageFile.GetThumbnailImage(ThumbWidth,ThumbHeight,ImageAbortCallBack,IntPtr.Zero) 'IntPtr=Aplatform-specifictypethatisusedtorepresentapointerorahandle. imageFile.Save(inDestinationFile,System.Drawing.Imaging.ImageFormat.Jpeg) outputFstream.Close() outputFstream=Nothing imageFile=Nothing EndFunction
希望本文所述对大家的asp.net程序设计有所帮助。