/// <summary> /// Crops image /// </summary> private static void Crop() { using (var bitmap = new Bitmap("../../../../_Input/Chicago.jpg")) { bitmap.Transforms.Crop(230, 170, 320, 240); bitmap.Save("../../../../_Output/Crop.jpg"); } }
/// <summary> /// Tints using alpha channel /// </summary> private static void TintUsingAlpha(RgbColor color) { using (var bitmap = new Bitmap("../../../../_Input/Chicago.jpg")) { using (var result = new Aurigma.GraphicsMill.Bitmap(bitmap.Width, bitmap.Height, PixelFormat.Format24bppRgb, color)) { bitmap.ColorManagement.Convert(PixelFormat.Format8bppGrayscale); bitmap.Transforms.Invert(); result.Channels.SetAlpha(bitmap); result.Channels.RemoveAlpha(RgbColor.White); result.Save("../../../../_Output/TintUsingAlpha_" + color.ToString() + ".jpg"); } } }
/// <summary> /// Writes EXIF and IPTC metadata /// </summary> private static void WriteExifIptc() { using (var bitmap = new Aurigma.GraphicsMill.Bitmap("../../../../_Input/Chicago.jpg")) { var settings = new Aurigma.GraphicsMill.Codecs.JpegSettings(70); var exif = new Aurigma.GraphicsMill.Codecs.ExifDictionary(); exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Software] = "Aurigma Graphics Mill"; settings.Exif = exif; var iptc = new Aurigma.GraphicsMill.Codecs.IptcDictionary(); iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword] = "mountain"; iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.City] = "Olympia"; settings.Iptc = iptc; bitmap.Save("../../../../_Output/WriteExifIptc.jpg", settings); } }
protected override TaskOutput Execute(TaskInput input, ITaskContext context) { foreach (var file in input.Files) { try { IEncoderOptions options = new JpegEncoderOptions(90, false); switch (_convertFormat) { case ConvertFormat.Jpeg: options = new JpegEncoderOptions(90, false); break; case ConvertFormat.Png: options = new PngEncoderOptions(); break; case ConvertFormat.Tiff: options = new TiffEncoderOptions(CompressionType.Zip); break; } var isConverted = false; using (var readStream = new FileStream(file.Path, FileMode.Open)) { using (var reader = FormatManager.CreateFormatReader(readStream)) { if (reader.MediaFormat != options.MediaFormat) { using (var frame = reader.LoadFrame(0)) { using (var resultBitmap = new Bitmap(frame.Width, frame.Height, Aurigma.GraphicsMill.PixelFormat.Format24bppRgb)) { frame.GetBitmap(resultBitmap); var conveter = new PixelFormatConverter { DestinationPixelFormat = Aurigma.GraphicsMill.PixelFormat.Format32bppArgb }; conveter.ApplyTransform(resultBitmap); if (resultBitmap.HasAlpha) { resultBitmap.Channels.DiscardAlpha(RgbColor.White); } resultBitmap.Save(file.Path + ".tmp", options); isConverted = true; } } } } } if (isConverted) { File.Delete(file.Path); File.Move(file.Path + ".tmp", file.Path); } } catch (System.Exception ex) { Logger.ErrorException(string.Format("Error while converting file {1} to {0}", _convertFormat, file.Path), ex); } } return(new TaskOutput(input.Files, input.Params)); }
protected override TaskOutput Execute(TaskInput input, ITaskContext context) { foreach (var taskFile in input.Files) { var textNote = taskFile.Params[_textKey]; var textPosition = taskFile.Params[_positionKey]; using (var image = new Bitmap(taskFile.Path)) { if (!image.IsRgb || image.IsIndexed || image.IsGrayScale) { image.ColorManagement.ConvertToContinuous(ColorSpace.Rgb, false, false); } var renderingSize = new Size(image.Width, image.Height); double materialWidth = (double)renderingSize.Width / 100; double materialHeight = (double)renderingSize.Height / 100; double lineSize = 0; if (textPosition == "Left" || textPosition == "Right") { lineSize = materialWidth / 15; materialWidth -= lineSize; } else { lineSize = materialHeight / 15; materialHeight -= lineSize; } int textWidth = 0; int textHeight = (int)Math.Round(lineSize * image.Height / materialHeight); if (textPosition == "Left" || textPosition == "Right") { textWidth = image.Height; } else { textWidth = image.Width; } using (Bitmap text = new Bitmap(System.Drawing.Color.FromArgb(240, 240, 240), textWidth, textHeight, PixelFormat.Format32bppArgb)) { using (Graphics graphics = text.GetGdiplusGraphics()) { System.Drawing.Color sourceColor = System.Drawing.Color.White; System.Drawing.Color destColor = System.Drawing.Color.White; if (textPosition == "Left" || textPosition == "Top") { sourceColor = System.Drawing.Color.FromArgb(200, 200, 200); } else { destColor = System.Drawing.Color.FromArgb(200, 200, 200); } var gradient = new LinearGradientBrush(new Rectangle(0, 0, text.Width, text.Height), sourceColor, destColor, LinearGradientMode.Vertical); graphics.FillRectangle(gradient, 0, 0, text.Width, text.Height); using (var drawFont = new Aurigma.GraphicsMill.Drawing.Font("Trebuchet MS", textHeight / 2)) { drawFont.Antialiased = true; drawFont.Unit = Unit.Point; drawFont.ClearType = true; using (var drawBrush = new SolidBrush(System.Drawing.Color.Black)) { var drawFormat = new StringFormat(); drawFormat.Alignment = StringAlignment.Center; drawFormat.LineAlignment = StringAlignment.Center; graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; graphics.DrawString(textNote, drawFont, drawBrush, new RectangleF(0, 0, textWidth, textHeight), drawFormat); } } } int resultWidth = image.Width; int resultHeight = image.Height; if (textPosition == "Left" || textPosition == "Right") { text.Transforms.RotateAndFlip(RotateFlipType.Rotate270FlipNone); resultWidth += text.Width; } else { resultHeight += text.Height; } using (var result = new Bitmap(resultWidth, resultHeight, PixelFormat.Format32bppArgb)) { switch (textPosition) { case "Left": text.Draw(result, 0, 0, CombineMode.AlphaOverlapped, 1.0f); image.Draw(result, text.Width, 0, CombineMode.AlphaOverlapped, 1.0f); break; case "Right": text.Draw(result, image.Width, 0, CombineMode.AlphaOverlapped, 1.0f); image.Draw(result, 0, 0, CombineMode.AlphaOverlapped, 1.0f); break; case "Top": text.Draw(result, 0, 0, CombineMode.AlphaOverlapped, 1.0f); image.Draw(result, 0, text.Height, CombineMode.AlphaOverlapped, 1.0f); break; default: text.Draw(result, 0, image.Height, CombineMode.AlphaOverlapped, 1.0f); image.Draw(result, 0, 0, CombineMode.AlphaOverlapped, 1.0f); break; } var pngEncoder = new PngEncoderOptions(); result.Save(taskFile.Path, pngEncoder); } } } } return(new TaskOutput(input.Files, input.Params)); }
private void CreateThumbs(string scanTargetPath) { string thisJob = scanTargetPath.Replace(@"\\photoserver\FilmSystem\Orders\", "").Replace(@"\1 - Scanned", "").Replace(@"\5 - Rescanned", ""); string thumbPath = Path.Combine(scanTargetPath, "0 - Thumbs").Replace(@"\1 - Scanned", ""); DirectoryInfo di = new DirectoryInfo(scanTargetPath); FileInfo[] fileList = di.GetFiles("*_*.jpg"); using (LoadingMessage lm = new LoadingMessage()) { lm.ChangeMessage("No thumbnails found. Crushing " + fileList.Count() + " images from job " + thisJob + "."); lm.StartPosition = FormStartPosition.CenterScreen; lm.Show(); Application.DoEvents(); foreach (FileInfo file in fileList) { using (var bitmap = new Aurigma.GraphicsMill.Bitmap(file.FullName)) { bitmap.Transforms.Resize(700, 0); bitmap.Save(Path.Combine(thumbPath, thisJob + "_" + file.Name)); } } CopyThumbs(thumbPath, fileList.Count(), thisJob); lm.Close(); } }
private void SquishImages() { DirectoryInfo di = new DirectoryInfo(ccFolder); FileInfo[] files = di.GetFiles("*_*_*.jpg"); foreach (var file in files) { using (var bitmap = new Aurigma.GraphicsMill.Bitmap(file.FullName)) { bitmap.Transforms.Resize(700, 0); bitmap.Save(Path.Combine(thumbsFolder, file.Name)); } } }