Created
July 1, 2014 18:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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