我正在使用内存流通过 FileUpload 控件调整图像大小。在它调整大小后,我希望它保存到我的文件系统中"~/images/2012/" + filename
。
如何从内存流中保存图像?
System.Drawing.Image imageLarge = System.Drawing.Image.FromStream(stream);
System.Drawing.Image imageLarge1 = ResizeImage(imageLarge, 200, 300);
MemoryStream memolarge = new MemoryStream();
imageLarge1.Save(memolarge, System.Drawing.Imaging.ImageFormat.Jpeg);
System.Drawing.Image returnImage = System.Drawing.Image.FromStream(memolarge);
Encoder myEncoder;
EncoderParameter myEncoderParameter;
EncoderParameters myEncoderParameters;
myEncoder = Encoder.Quality;
myEncoderParameter = new EncoderParameter(myEncoder, 100L);
myEncoderParameters.Param[0] = myEncoderParameter;
string convertedImage = returnImage.ToString();
returnImage.Save("~/images/2012/" + filename,
ImageFormat.Jpeg, myEncoderParameters);
这是我与重载方法错误相处的错误:
无法从“System.Drawing.Imaging.ImageFormat”转换为 System.Drawing.Imaging.ImageCodecInfo