Skip to content

Instantly share code, notes, and snippets.

@weslley39
Created July 1, 2014 18:41
Show Gist options
  • Save weslley39/30ce2c4c7ccff4a402da to your computer and use it in GitHub Desktop.
Save weslley39/30ce2c4c7ccff4a402da to your computer and use it in GitHub Desktop.
Resize the image in C# for the size that you want, in format of PNG
int newHeight = 110;
int newWidth = 110;
//REDIMENCIONA A IMAGEM PARA 110X110 EM PNG
if (!string.IsNullOrEmpty(avatarIdAntigo)) _fileService.ExcluirPorId(avatarIdAntigo);
Image streamToImage = Image.FromStream(imagem.InputStream);
Bitmap newImageResized = new Bitmap(newWidth, newHeight);
using (Graphics gr = Graphics.FromImage(newImageResized))
{
gr.SmoothingMode = SmoothingMode.HighQuality;
gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
gr.PixelOffsetMode = PixelOffsetMode.HighQuality;
gr.DrawImage(streamToImage, new Rectangle(0, 0, newWidth, newHeight));
}
var newImageStream = new MemoryStream();
newImageResized.Save(newImageStream, ImageFormat.Png);
_fileService.Adicionar(newImageStream,
new GridFSImportSettings()
{
FileName = filename,
ContentType = "image/png",
Id = avatarId
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment