protected void Button1_Click(object sender, EventArgs e)
{
string ext = null, path = null, newFileName = null;
System.Drawing.Image image, newImage;
if (FileUpload1.PostedFile.FileName != null && FileUpload1.PostedFile.FileName != "")
{
//载入原图
image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream);
//回调
System.Drawing.Image.GetThumbnailImageAbort callb = new System.Drawing.Image.GetThumbnailImageAbort(callBack);
//生成缩略图
newImage = image.GetThumbnailImage(image.Width / 3, image.Height / 3, callb, new System.IntPtr());
image.Dispose();
newImage.Dispose();
if (FileUpload1.PostedFile != null)
{
//判断是不是图像文件
if (FileUpload1.PostedFile.ContentType.ToLower().IndexOf("image") < 0)
{
Response.Write("文件类型错误");//文件类型错误
}
else
{
ext = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf("."));
//生成新的原文件名 年月日+文件大小+扩展名
path = "upload/" + System.DateTime.Now.Date.ToShortDateString() + FileUpload1.PostedFile.ContentLength.ToString() + ext;
//缩略图文件名
newFileName = "upload/" + System.DateTime.Now.Date.ToShortDateString() + FileUpload1.PostedFile.ContentLength.ToString() + "small" + ext;
//上传缩略图
Bitmap output = new Bitmap(newImage);
//Graphics g = Graphics.FromImage(output);
//output.Save(Server.MapPath(newFileName));
output.save(newFileName);
//FileUpload1.PostedFile.SaveAs(Server.MapPath(newFileName));
FileUpload1.PostedFile.SaveAs(Server.MapPath(path));
}
}
}
else
{
path = null;
newFileName = null;
}
}
标记的那句话有错,应该怎么改呀?大家帮帮忙!谢谢!