我正在使用fileapi插件上传c#中的图像。我的实际文件大小是60kb,但上传后,服务器上的文件大小显示为350kb。为什么会这样?以下是我保存图像的代码:
public JsonResult SaveImageFile(byte[] file)
{
var filesData = Request.Files[0];
string fileName = System.DateTime.Now.ToString("yyyyMMddHHmmssffff");
if (filesData != null && filesData.ContentLength > 0)
{
string directoryPath = Path.Combine(Server.MapPath("~/Images/Products/"), itemId);
string filePath = Path.Combine(Server.MapPath("~/Images/Products/"), itemId, fileName+".jpeg");
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
Image img = Image.FromStream(filesData.InputStream, true, true);
img = img.GetThumbnailImage(800, 600, () => false, IntPtr.Zero);
img.Save(Path.ChangeExtension(filePath, "jpeg"));
Image thumb = img.GetThumbnailImage(411, 274, () => false, IntPtr.Zero);
thumb.Save(Path.ChangeExtension(filePath, "png"));
ViewBag.MimeType = "image/pjpeg";
TempData["ItemFilePath"] = "~/Images/Products/" + itemId +"/"+ fileName+".jpeg";
TempData["ItemThumbnailFilePath"] = "~/Images/Products/" + itemId + "/" + fileName + ".png";
TempData["ItemFileName"] = fileName + ".jpeg";
}
return Json(new
{
Success = true,
Title = "Success",
FileName = relativePath
}, JsonRequestBehavior.AllowGet);
}
有人能告诉我我的代码有什么问题吗?我正在设计购物车,其中图像大小必须很小。缩略图图像(
png
)还需要更大的200kb大小