以下是引用片段
privatevoidbtnUploadPicture_Click(objectsenderSystemEventArgse)
{
//检查上传文件的格式是否有效
if(thisUploadFilePostedFileContentTypeToLower()IndexOf(image)<)
{
ResponseWrite(上传图片格式无效!);
return;
}
//生成原图
Byte[]oFileByte=newbyte[thisUploadFilePostedFileContentLength];
SystemIOStreamoStream=thisUploadFilePostedFileInputStream;
SystemDrawingImageoImage=SystemDrawingImageFromStream(oStream);
intoWidth=oImageWidth;//原图宽度
intoHeight=oImageHeight;//原图高度
inttWidth=;//设置缩略图初始宽度
inttHeight=;//设置缩略图初始高度
//按比例计算出缩略图的宽度和高度
if(oWidth>=oHeight)
{
tHeight=(int)MathFloor(ConvertToDouble(oHeight)*(ConvertToDouble(tWidth)/ConvertToDouble(oWidth)));
}
else
{
tWidth=(int)MathFloor(ConvertToDouble(oWidth)*(ConvertToDouble(tHeight)/ConvertToDouble(oHeight)));
}
//生成缩略原图
BitmaptImage=newBitmap(tWidthtHeight);
Graphicsg=GraphicsFromImage(tImage);
gInterpolationMode=SystemDrawingDrawingDInterpolationModeHigh;//设置高质量插值法
gSmoothingMode=SystemDrawingDrawingDSmoothingModeHighQuality;//设置高质量低速度呈现平滑程度
gClear(ColorTransparent);//清空画布并以透明背景色填充
gDrawImage(oImagenewRectangle(tWidthtHeight)newRectangle(oWidthoHeight)GraphicsUnitPixel);
stringoFullName=ServerMapPath()+/+o+DateTimeNowToShortDateString()Replace()+DateTimeNowHourToString()+DateTimeNowMinuteToString()+DateTimeNowSecondToString()+DateTimeNowMillisecondToString()+jpg;//保存原图的物理路径
stringtFullName=ServerMapPath()+/+t+DateTimeNowToShortDateString()Replace()+DateTimeNowHourToString()+DateTimeNowMinuteToString()+DateTimeNowSecondToString()+DateTimeNowMillisecondToString()+jpg;//保存缩略图的物理路径
try
{
//以JPG格式保存图片
oImageSave(oFullNameSystemDrawingImagingImageFormatJpeg);
tImageSave(tFullNameSystemDrawingImagingImageFormatJpeg);
}
catch(Exceptionex)
{
throwex;
}
finally
{
//释放资源
oImageDispose();
gDispose();
tImageDispose();
}
}