0
i am trying to implement a code to do image resizing because currently are uploading very large images on my system, however I am not able to perform resizing proportionally.
Follows the code in Asp.net-core MVC
public async Task<string> SalvarImagemPBlog(long RedeId, IFormFile File, long BlogId, long ImagemId)
{
byte[] Arquivo = Convert.FromBase64String(PrepararArquivoBase64(File));
Image image;
//Converte byte[] para image
using (MemoryStream ms = new MemoryStream(Arquivo))
{
image = Image.FromStream(ms);
}
// Resize a imagem
Bitmap b = new Bitmap(400, 400);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
//Alterar o DrawImage onde ta 200,200 caso apareça uma parte preta na imagem
//Colocar no mesmo tamanho do resize
g.DrawImage(image, 0, 0, 400, 400);
g.Dispose();
image = (Image)b;
using (MemoryStream ms = new MemoryStream())
{
// Converte Image para byte[]
image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
Arquivo = ms.ToArray();
}
return await SalvarArquivoBlob($"{this.Diretorio}/{RedeId}/Blog/{BlogId}", Arquivo, $"{File.FileName}");
}