图片转换成Byte[]
在我之前用的代码是这样的。。结果图片一大 就内存不够用。。
Bitmap image = new Bitmap(fileName); MemoryStream stream = new MemoryStream(); image.Save(stream, System.Drawing.Imaging.ImageFormat.Png); return stream.ToArray();
应该把代码改成这样。然后在把 Web.config maxRequestLength="196000" 改小一点
FileStream sFile = new FileStream(fileName, FileMode.Open); //获取文件长度 int nFileLength = (int) sFile.Seek(0, SeekOrigin.End); //修正偏移 sFile.Seek(0, SeekOrigin.Begin); //申请空间 byte[] btFile = new byte[nFileLength]; //读文件 sFile.Read(btFile, 0, nFileLength); sFile.Close(); return btFile;
这样就可以上传20MB左右的图片了。。