I'm trying to resize an image from stream. Getting the error
Value cannot be null.Parameter name: encoder
on the line
System.Drawing.Bitmap fullSizeBitmap = new System.Drawing.Bitmap(fullsizeImage, new System.Drawing.Size(width, image_height));
How do I add an encoder here? and I need it to be from the original image
public static FileProperty UploadImage(IFormFile file, string folderPath, string fileName, FileNote note, int image_height)
{
FileProperty property = new FileProperty();
if (file.Length > 0)
{
MemoryStream ms = new MemoryStream();
file.CopyTo(ms);
var fileBytes = ms.ToArray();
MemoryStream inputMemoryStream = new MemoryStream(fileBytes);
System.Drawing.Image fullsizeImage = System.Drawing.Image.FromStream(inputMemoryStream);
int width = (image_height / fullsizeImage.Height) * fullsizeImage.Width;
System.Drawing.Bitmap fullSizeBitmap = new System.Drawing.Bitmap(fullsizeImage, new System.Drawing.Size(width, image_height));
using (var stream = new MemoryStream())
{
fullSizeBitmap.Save(stream, fullSizeBitmap.RawFormat);
using (MemoryStream memoryStream = new MemoryStream(stream.ToArray()))
{
UploadFromStreamAsync(memoryStream);
}
}
property.FileName = fileName;
property.FileExtention = Path.GetExtension(fileName);
property.FileSize = file.Length;
property.FileType = file.ContentType;
property.FileNote = note.ToString();
}
return property;
}