从文件构造位图对象或图像对象时,文件在对象的生存期内保持锁定状态。因此,您无法更改图像并将其保存回其原始位置。
http://support.microsoft.com/?id=814675
GDI
+,JPEG图像到MemoryStream中发生一般错误
Image.Save(..)抛出GDI
+异常,因为内存流已关闭
http://alperguc.blogspot.in/2008/11/c-generic-error-occurred-in-
gdi.html
编辑:
只是从内存写入…
保存到“中间”内存流,应该可以
例如尝试这个-替换
Bitmap newBitmap = new Bitmap(thumbBMP); thumbBMP.Dispose(); thumbBMP = null; newBitmap.Save("~/image/thumbs/" + "t" + objPropBannerImage.ImageId, ImageFormat.Jpeg);
与类似:
string outputFileName = "...";using (MemoryStream memory = new MemoryStream()){ using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite)) { thumbBMP.Save(memory, ImageFormat.Jpeg); byte[] bytes = memory.ToArray(); fs.Write(bytes, 0, bytes.Length); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)