我想减小上传到服务器时的图像大小。
查看
@using (Html.BeginForm("UserCUD", "User", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="form-group col-md-3">
<label id="lblImage" for="userImage">Image</label>
<input type="file" class="form-control-file" value="Image" title=" " id="userImage" name="userImage" accept=".jpg">
</div>
}
在我的控制器中,这是我操作图像的方式
控制器
public ActionResult UserCUD(FormCollection collection, HttpPostedFileBase userImage)
{
if (userImage != null)
{
string pic = System.IO.Path.GetFileName(SOMEID);
string path = System.IO.Path.Combine(Server.MapPath("~/Img/Users"), pic);
userImage.SaveAs(path);
using (MemoryStream ms = new MemoryStream())
{
userImage.InputStream.CopyTo(ms);
byte[] array = ms.GetBuffer();
}
}
}
问题
如果图像真的很重/很大,是否有减小图像尺寸的方法?