protected override void LoadControlState(object savedState) { string[] state = (string[])savedState; if (!Int32.TryParse(state[0], out intImageWidth)) intImageWidth = -1; if (!Int32.TryParse(state[1], out intImageHeight)) intImageHeight = -1; serverImgID = state[2]; originalSrc = state[3]; controlMode = (ControlMode)Enum.Parse(typeof(ControlMode), state[4]); hasChanged = (state[5] == "1"); if (!Int32.TryParse(state[6], out canvasWidth)) canvasWidth = 0; if (!Int32.TryParse(state[7], out canvasHeight)) canvasHeight = 0; workingDirectory = state[8]; webImageFormat = (WebImageFormat)Enum.Parse(typeof(WebImageFormat), state[9]); webImageQuality = (WebImageQuality)Enum.Parse(typeof(WebImageQuality), state[10]); if (!Int32.TryParse(state[11], out rawWidth)) rawWidth = 0; if (!Int32.TryParse(state[12], out rawHeight)) rawHeight = 0; canvasImageName = state[13]; webImageName = state[14]; handlerPath = state[15]; if (!Single.TryParse(state[16], out aspectRatio)) aspectRatio = 0; if (!Int32.TryParse(state[17], out thumbnailSize)) thumbnailSize = 64; }
public string SaveRawImageAsWebImage(WebImageFormat format, WebImageQuality quality) { string filePath = getFilePath(WebImageMaker.WebImageDirName, format); using (Image img = Image.FromFile(getRawFilePath())) { // if the raw image is the same format then just copy the raw image: if (getGDIFormat(format).Equals(img.RawFormat)) { File.Copy(getRawFilePath(), filePath); } else { // we need to do some conversion, but don't bother with quality settings - // if it's the wrong format then the quality isn't going to be great anyway img.Save(filePath, getGDIFormat(format)); } } return Path.GetFileName(filePath); }
public string CreateCanvas(WebImageFormat format, WebImageQuality quality, int canvasWidth, int canvasHeight) { purge(WebImageMaker.CanvasImageDirName); string canvasFileName = null; using (Image rawImg = Image.FromFile(getRawFilePath())) { using (Bitmap canvas = new Bitmap(canvasWidth, canvasHeight, PixelFormat.Format24bppRgb)) { using (Graphics g = Graphics.FromImage(canvas)) { setGraphicsQuality(g, quality); g.DrawImage(rawImg, 0, 0, canvasWidth, canvasHeight); string filePath = getFilePath(WebImageMaker.CanvasImageDirName, format); canvas.Save(filePath, getGDIFormat(format)); canvasFileName = Path.GetFileName(filePath); } } } return canvasFileName; }
public string CropAndScale(System.Drawing.Rectangle transformedSelection, WebImageFormat format, WebImageQuality quality, int reqdWidth, int reqdHeight) { if (reqdWidth < 1) { reqdWidth = 100; } if (reqdHeight < 1) { reqdHeight = 100; } string webFileName = null; Rectangle dest = new Rectangle(0, 0, reqdWidth, reqdHeight); using (Image rawImg = Image.FromFile(getRawFilePath())) { using (Bitmap webImage = new Bitmap(reqdWidth, reqdHeight, PixelFormat.Format24bppRgb)) { using (Graphics g = Graphics.FromImage(webImage)) { setGraphicsQuality(g, quality); g.DrawImage(rawImg, dest, transformedSelection, GraphicsUnit.Pixel); string filePath = getFilePath(WebImageMaker.WebImageDirName, format); webImage.Save(filePath, getGDIFormat(format)); webFileName = Path.GetFileName(filePath); } } } return webFileName; }
private void setGraphicsQuality(Graphics g, WebImageQuality quality) { switch (quality) { case WebImageQuality.High: g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; break; case WebImageQuality.Medium: g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; break; case WebImageQuality.Low: g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighSpeed; g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; break; } }