1.定义保存路径
fileAllPath = fileDirectory.TrimEnd('\\') + "/Uploadfiles/" + newname + suffix
2.附件控件submit提交表单后获取HttpPostedFile对象,假设是单个文件上传
HttpPostedFile fup_Upload1 = context.Request.Files[0];
3.定义源文件对象System.Drawing.Image,然后创建缩小后文件对象System.Drawing.Bitmap,并设置缩小后的宽度和高度
System.Drawing.Image image = new System.Drawing.Bitmap(fup_Upload1.InputStream);
伪代码如下:
fileAllPath = fileDirectory.TrimEnd('\\') + "/Uploadfiles/" + newname + suffix
HttpPostedFile fup_Upload1 = context.Request.Files[0];
System.Drawing.Image image = new System.Drawing.Bitmap(fup_Upload1.InputStream);if (image != null)
{
wFile.P_height = 640;
wFile.P_width = 450;
System.Drawing.Bitmap bitSmallImage = new System.Drawing.Bitmap(image, wFile.P_width, wFile.P_height);
bitSmallImage.Save(fileAllPath);
}