Created
February 6, 2015 14:46
-
-
Save jmprado/06f2064ca0578f25d773 to your computer and use it in GitHub Desktop.
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
using (Graphics graphics = Graphics.FromImage(resized)) | |
{ | |
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; | |
graphics.SmoothingMode = SmoothingMode.HighQuality; | |
graphics.CompositingQuality = CompositingQuality.HighQuality; | |
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; | |
graphics.DrawImage(imagemOriginal, new Rectangle(0, 0, resized.Width, resized.Height), new Rectangle(0, 0, imagemOriginal.Width, imagemOriginal.Height), GraphicsUnit.Pixel); | |
if (addWaterMark == "1") | |
{ | |
string filePath = context.HttpContext.Server.MapPath("~/Content/logotrans.png"); | |
if (File.Exists(filePath)) | |
{ | |
using (Bitmap bmLogo = new Bitmap(filePath)) | |
{ | |
int widthLogo = bmLogo.Width; | |
int heightLogo = bmLogo.Height; | |
const int posHorizontal = 20; | |
const int posVertical = 20; | |
graphics.DrawImage(bmLogo, new Point(posHorizontal, posVertical)); | |
} | |
} | |
} | |
} | |
const int quality = 90; | |
System.Drawing.Imaging.EncoderParameters encoderParameters = new System.Drawing.Imaging.EncoderParameters(1); | |
encoderParameters.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality); | |
byte[] buffer = null; | |
using (MemoryStream stream = new MemoryStream()) | |
{ | |
resized.Save(stream, GetImageCodeInfo("image/jpeg"), encoderParameters); | |
buffer = stream.ToArray(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment