Yüklenen bir görüntüyü MVC 6'da yeniden boyutlandırmanın en iyi yolu nedir? Daha sonra görüntülenecek olanı seçmek için bir görüntünün (örneğin, küçük, büyük, vb.) Birden çok çeşidini saklamak istiyorum.Yüklenen resmi MVC'ye yeniden boyutlandırma 6
İşte eylem için kodum.
[HttpPost]
public async Task<IActionResult> UploadPhoto()
{
if (Request.Form.Files.Count != 1)
return new HttpStatusCodeResult((int)HttpStatusCode.BadRequest);
IFormFile file = Request.Form.Files[0];
// calculate hash
var sha = System.Security.Cryptography.SHA256.Create();
byte[] hash = sha.ComputeHash(file.OpenReadStream());
// calculate name and patch where to store the file
string extention = ExtentionFromContentType(file.ContentType);
if (String.IsNullOrEmpty(extention))
return HttpBadRequest("File type not supported");
string name = WebEncoders.Base64UrlEncode(hash) + extention;
string path = "uploads/photo/" + name;
// save the file
await file.SaveAsAsync(this.HostingEnvironment.MapPath(path));
}
Teşekkürler! Tam olarak ihtiyacım olan şey! –
@Phill Harika bağlantı, teşekkürler, vNext görüntüsü için bulduğum tek şey. Ama "Yeni Boyut" System.Drawing kısmı mı? – Alex
@voo geçerli Nuget hala System.Drawing gerektirir, ancak API bu kısıtlamayı bırakmak için V2 için değişiyor. https://github.com/JimBobSquarePants/ImageProcessor#api-changes – Phill