我有图片上传功能。
有没有人知道如何从HttpPostedFileBase减小JPG图像的大小而不必将文件保存到硬盘?如果可能的话,我想把这一切都留在记忆里。
[HttpPost]
public ActionResult UploadMultipleImages(List<HttpPostedFileBase> files)
{
Decimal decTN = Convert.ToDecimal(Request.Form["TN"].ToString());
Decimal decCN = Convert.ToDecimal(Request.Form["CN"].ToString());
Parallel.ForEach(files, file =>
{
String extension = Path.GetExtension(file.FileName);
String strTitleForImage = Request.Form["TitleOfImage"].ToString();
String strDescription = Request.Form["Description"].ToString();
Int32 intDateTaken = Convert.ToInt32(Request.Form["DateTaken"].ToString().Replace("-", ""));
String strBase64Value = "";
Stream inputStream = file.InputStream;
// Can I reduce JPG file here in memory?
strBase64Value = ToBase64(inputStream);
InsertImage(decTN, strTitleForImage, intDateTaken, strDescription, strBase64Value);
}
});
return RedirectToAction("Index/" + decTN + "/" + decCN);
}