要保存图像,我使用以下代码:
string filenamewithpath =
System.Web.HttpContext.Current.Server.MapPath(
@"~/userimages/" + incID + ".jpg");
System.IO.File.WriteAllBytes(filenamewithpath, Util.ReadFully(image));
public class Util
{
public static byte[] ReadFully(Stream stream)
{
byte[] buffer = new byte[32768];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = stream.Read(buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write(buffer, 0, read);
}
}
}
}
以上适用于使用 ID 保存图像。更新时,我需要覆盖现有图像,并且需要一些有关如何执行此操作的建议。