下载

0下载券

加入VIP
  • 专属下载特权
  • 现金文档折扣购买
  • VIP免费专区
  • 千万文档免费下载

上传资料

关闭

关闭

关闭

封号提示

内容

首页 按比例缩小照片

按比例缩小照片.doc

按比例缩小照片

詠恆啲诺琂_
2018-08-03 0人阅读 举报 0 0 0 暂无简介

简介:本文档为《按比例缩小照片doc》,可适用于综合领域

按比例缩小照片<summary>按比例缩小图片自动计算宽度<summary><paramname="strOldPic">源图文件名(包括路径)<param><paramname="strNewPic">缩小后保存为文件名(包括路径)<param><paramname="intHeight">缩小至高度<param>publicvoidSmallPicWidth(stringstrOldPic,stringstrNewPic,intintHeight){SystemDrawingBitmapobjPic,objNewPictry{objPic=newSystemDrawingBitmap(strOldPic)intintWidth=(intHeightobjPicHeight)*objPicWidthobjNewPic=newSystemDrawingBitmap(objPic,intWidth,intHeight)objNewPicSave(strNewPic)}catch(Exceptionexp){throwexp}finally{objPic=objNewPic=}}**<summary>缩小图片<summary><paramname="strOldPic">源图文件名(包括路径)<param><paramname="strNewPic">缩小后保存为文件名(包括路径)<param><paramname="intWidth">缩小至宽度<param><paramname="intHeight">缩小至高度<param>publicvoidSmallPic(stringstrOldPic,stringstrNewPic,intintWidth,intintHeight){SystemDrawingBitmapobjPic,objNewPictry{objPic=newSystemDrawingBitmap(strOldPic)objNewPic=newSystemDrawingBitmap(objPic,intWidth,intHeight)objNewPicSave(strNewPic)}catch(Exceptionexp){throwexp}finally{objPic=objNewPic=}}aspnet图片上传(文件按日期命名真正意义上类型判断缩略图)作者:小角色来源:博客园发布时间::阅读:次原文链接收藏ImageThumbnailcs(生成缩略图文件)usingSystemusingSystemIOusingSystemDrawingusingSystemDrawingImagingpublicclassImageThumbnail{publicImageResourceImageprivateintImageWidthprivateintImageHeightpublicstringErrorMessagepublicImageThumbnail(stringImageFileName){ResourceImage=ImageFromFile(ImageFileName)ErrorMessage=""}publicboolThumbnailCallback(){returnfalse}方法按大小publicboolReducedImage(intWidth,intHeight,stringtargetFilePath){try{ImageReducedImageImageGetThumbnailImageAbortcallb=newImageGetThumbnailImageAbort(ThumbnailCallback)ReducedImage=ResourceImageGetThumbnailImage(Width,Height,callb,IntPtrZero)ReducedImageSave(targetFilePath,ImageFormatJpeg)ReducedImageDispose()returntrue}catch(Exceptione){ErrorMessage=eMessagereturnfalse}}方法按百分比缩小Percent为targetFilePath为目标路径publicboolReducedImage(doublePercent,stringtargetFilePath){try{ImageReducedImageImageGetThumbnailImageAbortcallb=newImageGetThumbnailImageAbort(ThumbnailCallback)ImageWidth=ConvertToInt(ResourceImageWidth*Percent)ImageHeight=(ResourceImageHeight)*ImageWidthResourceImageWidth等比例缩放ReducedImage=ResourceImageGetThumbnailImage(ImageWidth,ImageHeight,callb,IntPtrZero)ReducedImageSave(targetFilePath,ImageFormatJpeg)ReducedImageDispose()returntrue}catch(Exceptione){ErrorMessage=eMessagereturnfalse}}}前台文件:就一个FileUpload和一个Button,就不用贴代码了吧!usingSystemusingSystemDatausingSystemConfigurationusingSystemCollectionsusingSystemWebusingSystemWebSecurityusingSystemWebUIusingSystemWebUIWebControlsusingSystemWebUIWebControlsWebPartsusingSystemWebUIHtmlControlspublicpartialclassDefault:SystemWebUIPage{protectedvoidPageLoad(objectsender,EventArgse){}protectedvoidbtnUploadClick(objectsender,EventArgse){try{判断是否已经选取文件if(FileUploadHasFile){if(IsAllowedExtension(FileUpload)){取得文件的扩展名,并转换成小写stringfileExtension=SystemIOPathGetExtension(FileUploadFileName)ToLower()stringpath=ServerMapPath("~Bigimages")stringpath=ServerMapPath("~Smallimages")stringfileName=DateRndName()fileExtensionFileUploadPostedFileSaveAs(pathfileName)生成缩略图并存进文件夹ImageThumbnailimg=newImageThumbnail(FileUploadPostedFileFileName)imgReducedImage(,,pathfileName),表是长和宽都为imgReducedImage(,pathfileName)表示缩小ResponseWrite("<script>alert("上传成功")<script>")}else{ResponseWrite("<script>alert("您只能上传jpg或者gif图片")<script>")}}else{ResponseWrite("<script>alert("你还没有选择文件")<script>")}}catch(Exceptionerror){ResponseWrite(errorToString())}}真正判断文件类型的关键函数publicstaticboolIsAllowedExtension(FileUploadhifile){SystemIOFileStreamfs=newSystemIOFileStream(hifilePostedFileFileName,SystemIOFileModeOpen,SystemIOFileAccessRead)SystemIOBinaryReaderr=newSystemIOBinaryReader(fs)stringfileclass=""bytebuffertry{buffer=rReadByte()fileclass=bufferToString()buffer=rReadByte()fileclass=bufferToString()}catch{}rClose()fsClose()if(fileclass==""||fileclass=="")说明是jpg是gif是BMP,是PNG是exe,是rar{returntrue}else{returnfalse}}#regionDateRndName()日期时间位数随机stringDateRndName(){Randomra=newRandom()DateTimed=DateTimeNowstrings=,y,m,dd,h,mm,ssy=dYearToString()m=dMonthToString()if(mLength<)m=""mdd=dDayToString()if(ddLength<)dd=""ddh=dHourToString()if(hLength<)h=""hmm=dMinuteToString()if(mmLength<)mm=""mmss=dSecondToString()if(ssLength<)ss=""sss=ymddhmmsss=raNext(,)ToString()returns}#endregion}

用户评价(0)

关闭

新课改视野下建构高中语文教学实验成果报告(32KB)

抱歉,积分不足下载失败,请稍后再试!

提示

试读已结束,如需要继续阅读或者下载,敬请购买!

评分:

/13

VIP

在线
客服

免费
邮箱

爱问共享资料服务号

扫描关注领取更多福利