public void MakeCards() { var deck = JsonConvert.DeserializeObject<Deck>(File.ReadAllText(@"C:\temp\testdeck.cm")); var cards = new List<MagickImage>(); foreach (var card in deck.Cards) { var image = new MagickImage(new MagickColor("WhiteSmoke"), deck.Width, deck.Height); image.Density = new MagickGeometry(300, 300); image.Format = MagickFormat.Bmp; foreach (var element in deck.Elements) { var data = card.ElementData[element.Key]; if (File.Exists(data)) { using (var overlayImage = new MagickImage(data)) { image.Composite(overlayImage, (int)element.Value.X, (int)element.Value.Y, CompositeOperator.Over); } } else { using (var textImage = new MagickImage(MagickColor.Transparent, deck.Width, deck.Height)) { textImage.Density = new MagickGeometry(300, 300); textImage.Font = "Arial"; textImage.FontPointsize = 12; textImage.FillColor = new MagickColor("Black"); var drawableText = new DrawableText(element.Value.X, element.Value.Y, data); textImage.Draw(drawableText); image.Composite(textImage, CompositeOperator.Over); } } } image.Write(string.Format(@"c:\temp\CardMaker\{0}.png", card.Name)); cards.Add(image); } using (var doc = new Document()) { PdfWriter.GetInstance(doc, new FileStream(@"C:\temp\CardMaker\cards.pdf", FileMode.Create)); doc.Open(); var columns = (int)Math.Floor(doc.PageSize.Width / (deck.Width + 10)); var table = new PdfPTable(columns) { WidthPercentage = 100, DefaultCell = { Border = 0, Padding = 5 } }; foreach (var card in cards) { var instance = Image.GetInstance(card.ToByteArray()); instance.SetDpi(300, 300); var cell = new PdfPCell(instance) { HorizontalAlignment = Element.ALIGN_CENTER, Border = 0, Padding = 5, }; table.AddCell(cell); } table.CompleteRow(); doc.Add(table); } }
private static TextSize DrawText(MagickImage image, string line, double[] spaces, double offsetX, double offsetY, Gravity position, bool measureOnly) { if (string.IsNullOrWhiteSpace(line)) { return(new TextSize(0d, 0d)); } image.Settings.TextAntiAlias = true; // image.Settings.TextInterwordSpacing = 0; // image.Settings.TextInterlineSpacing = 0; if (spaces == null || spaces.Length == 0) { if (!measureOnly) { var gravity = new DrawableGravity(position); var drawable = new DrawableText(offsetX, offsetY, line); image.Draw(drawable, gravity); } var metrics = Measure(image, line); return(new TextSize(metrics.TextWidth, metrics.Ascent - metrics.Descent)); } else { var words = line.Split(' '); var metrics = words.Select(x => Measure(image, x, true)).ToArray(); var totalSpace = words.Take(words.Length - 1).Select((x, i) => i < spaces.Length ? spaces[i] : spaces.LastOrDefault()).Sum(); var totalWidth = metrics.Select(x => x.TextWidth).Sum() + totalSpace; var totalHeight = metrics.Select(x => x.Ascent - x.Descent).Max(); if (!measureOnly) { double currentX, currentY; switch (position) { case Gravity.West: case Gravity.Northwest: case Gravity.Southwest: case Gravity.Undefined: currentX = offsetX; break; case Gravity.North: case Gravity.Center: case Gravity.South: currentX = image.Width / 2d - totalWidth / 2 + offsetX; break; case Gravity.East: case Gravity.Northeast: case Gravity.Southeast: currentX = image.Width - totalWidth - offsetX; break; default: currentX = 0d; break; } switch (position) { case Gravity.Northwest: case Gravity.North: case Gravity.Northeast: case Gravity.Undefined: currentY = offsetY; break; case Gravity.West: case Gravity.Center: case Gravity.East: currentY = image.Height / 2d - totalHeight / 2 + offsetY; break; case Gravity.Southwest: case Gravity.South: case Gravity.Southeast: currentY = image.Height - totalHeight - offsetY; break; default: currentY = 0d; break; } var gravity = new DrawableGravity(Gravity.Northwest); for (var i = 0; i < words.Length; i++) { if (!string.IsNullOrWhiteSpace(words[i])) { image.Draw(new DrawableText(currentX, currentY, words[i]), gravity); } currentX += metrics[i].TextWidth + (i < spaces.Length ? spaces[i] : spaces.LastOrDefault()); } } return(new TextSize(totalWidth, totalHeight)); } }
public void Test_Drawables() { PointD[] coordinates = new PointD[3]; coordinates[0] = new PointD(0, 0); coordinates[1] = new PointD(50, 50); coordinates[2] = new PointD(99, 99); using (IMagickImage image = new MagickImage(MagickColors.Transparent, 100, 100)) { image.Draw(new DrawableAffine(0, 0, 1, 1, 2, 2)); image.Draw(new DrawableAlpha(0, 0, PaintMethod.Floodfill)); image.Draw(new DrawableArc(0, 0, 10, 10, 45, 90)); var bezier = new DrawableBezier(coordinates.ToList()); Assert.AreEqual(3, bezier.Coordinates.Count()); image.Draw(bezier); image.Draw(new DrawableBorderColor(MagickColors.Fuchsia)); image.Draw(new DrawableCircle(0, 0, 50, 50)); image.Draw(new DrawableClipPath("foo")); image.Draw(new DrawableClipRule(FillRule.Nonzero)); image.Draw(new DrawableClipUnits(ClipPathUnit.UserSpaceOnUse)); image.Draw(new DrawableColor(0, 0, PaintMethod.Floodfill)); using (IMagickImage compositeImage = new MagickImage(new MagickColor("red"), 50, 50)) { image.Draw(new DrawableComposite(0, 0, compositeImage)); image.Draw(new DrawableComposite(0, 0, CompositeOperator.Over, compositeImage)); image.Draw(new DrawableComposite(new MagickGeometry(50, 50, 10, 10), compositeImage)); image.Draw(new DrawableComposite(new MagickGeometry(50, 50, 10, 10), CompositeOperator.Over, compositeImage)); } image.Draw(new DrawableDensity(97)); image.Draw(new DrawableEllipse(10, 10, 4, 4, 0, 360)); image.Draw(new DrawableFillColor(MagickColors.Red)); image.Draw(new DrawableFillOpacity(new Percentage(50))); image.Draw(new DrawableFillRule(FillRule.EvenOdd)); image.Draw(new DrawableFont("Arial.ttf")); image.Draw(new DrawableFont("Arial")); image.Draw(new DrawableGravity(Gravity.Center)); image.Draw(new DrawableLine(20, 20, 40, 40)); image.Draw(new DrawablePoint(60, 60)); image.Draw(new DrawableFontPointSize(5)); image.Draw(new DrawablePolygon(coordinates)); image.Draw(new DrawablePolygon(coordinates.ToList())); image.Draw(new DrawablePolyline(coordinates)); image.Draw(new DrawablePolyline(coordinates.ToList())); image.Draw(new DrawableRectangle(30, 30, 70, 70)); image.Draw(new DrawableRotation(180)); image.Draw(new DrawableRoundRectangle(30, 30, 50, 50, 70, 70)); image.Draw(new DrawableScaling(15, 15)); image.Draw(new DrawableSkewX(90)); image.Draw(new DrawableSkewY(90)); image.Draw(new DrawableStrokeAntialias(true)); image.Draw(new DrawableStrokeColor(MagickColors.Purple)); image.Draw(new DrawableStrokeDashArray(new double[2] { 10, 20 })); image.Draw(new DrawableStrokeDashOffset(2)); image.Draw(new DrawableStrokeLineCap(LineCap.Square)); image.Draw(new DrawableStrokeLineJoin(LineJoin.Bevel)); image.Draw(new DrawableStrokeMiterLimit(5)); image.Draw(new DrawableStrokeOpacity(new Percentage(80))); image.Draw(new DrawableStrokeWidth(4)); image.Draw(new DrawableText(0, 60, "test")); image.Draw(new DrawableTextAlignment(TextAlignment.Center)); image.Draw(new DrawableTextAntialias(true)); image.Draw(new DrawableTextDecoration(TextDecoration.LineThrough)); image.Draw(new DrawableTextDirection(TextDirection.RightToLeft)); image.Draw(new DrawableTextEncoding(Encoding.ASCII)); image.Draw(new DrawableTextInterlineSpacing(4)); image.Draw(new DrawableTextInterwordSpacing(6)); image.Draw(new DrawableTextKerning(2)); image.Draw(new DrawableTextUnderColor(MagickColors.Yellow)); image.Draw(new DrawableTranslation(65, 65)); image.Draw(new DrawableViewbox(0, 0, 100, 100)); image.Draw(new DrawablePushClipPath("#1"), new DrawablePopClipPath()); image.Draw(new DrawablePushGraphicContext(), new DrawablePopGraphicContext()); image.Draw(new DrawablePushPattern("test", 30, 30, 10, 10), new DrawablePopPattern(), new DrawableFillPatternUrl("#test"), new DrawableStrokePatternUrl("#test")); } }
public void Test_Drawables_Exceptions() { ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawableBezier(); }); ExceptionAssert.ThrowsArgumentNullException("coordinates", () => { new DrawableBezier(null); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawableBezier(new PointD[] { }); }); ExceptionAssert.ThrowsArgumentNullException("clipPath", () => { new DrawableClipPath(null); }); ExceptionAssert.ThrowsArgumentException("clipPath", () => { new DrawableClipPath(string.Empty); }); ExceptionAssert.ThrowsArgumentNullException("offset", () => { new DrawableComposite(null, new MagickImage(Files.Builtin.Logo)); }); ExceptionAssert.ThrowsArgumentNullException("image", () => { new DrawableComposite(new MagickGeometry(), null); }); ExceptionAssert.ThrowsArgumentNullException("color", () => { new DrawableFillColor(null); }); ExceptionAssert.ThrowsArgumentNullException("family", () => { new DrawableFont(null); }); ExceptionAssert.ThrowsArgumentException("family", () => { new DrawableFont(string.Empty); }); ExceptionAssert.Throws <MagickDrawErrorException>(() => { using (IMagickImage image = new MagickImage(Files.Builtin.Wizard)) { image.Draw(new DrawableFillPatternUrl("#fail")); } }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawablePolygon(new PointD[] { new PointD(0, 0) }); }); ExceptionAssert.ThrowsArgumentException("coordinates", () => { new DrawablePolyline(new PointD[] { new PointD(0, 0), new PointD(0, 0) }); }); ExceptionAssert.ThrowsArgumentNullException("color", () => { new DrawableStrokeColor(null); }); ExceptionAssert.ThrowsArgumentNullException("value", () => { new DrawableText(0, 0, null); }); ExceptionAssert.ThrowsArgumentException("value", () => { new DrawableText(0, 0, string.Empty); }); ExceptionAssert.ThrowsArgumentNullException("encoding", () => { new DrawableTextEncoding(null); }); }
/// <summary> /// Draw the bounds onto map /// </summary> /// <param name="map"></param> public void Draw(MagickImage map) { if (m_bounds.Count == 0) { return; } MainForm.ProgressStart("Drawing zone bounds ..."); // Sort the polygons List <List <PointD> > polygons = new List <List <PointD> >(); List <List <PointD> > negatedPolygons = new List <List <PointD> >(); foreach (List <PointF> polygon in m_bounds) { bool isClockwise = Tools.PolygonHasClockwiseOrder(polygon); var polygonConverted = polygon.Select(c => new PointD(zoneConfiguration.ZoneCoordinateToMapCoordinate(c.X), zoneConfiguration.ZoneCoordinateToMapCoordinate(c.Y))).ToList(); // polygons in clockwise order needs to be negated if (isClockwise) { negatedPolygons.Add(polygonConverted); } else { polygons.Add(polygonConverted); } } MagickColor backgroundColor = MagickColors.Transparent; if (polygons.Count == 0) { // There are no normal polygons, we need to fill the hole zone and substract negatedPolygons backgroundColor = m_boundsColor; } using (MagickImage boundMap = new MagickImage(backgroundColor, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { int progressCounter = 0; boundMap.Alpha(AlphaOption.Set); boundMap.Settings.FillColor = m_boundsColor; foreach (List <PointD> coords in polygons) { DrawablePolygon poly = new DrawablePolygon(coords); boundMap.Draw(poly); progressCounter++; int percent = 100 * progressCounter / m_bounds.Count(); MainForm.ProgressUpdate(percent); } if (negatedPolygons.Count > 0) { using (MagickImage negatedBoundMap = new MagickImage(Color.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { negatedBoundMap.Settings.FillColor = m_boundsColor; foreach (List <PointD> coords in negatedPolygons) { DrawablePolygon poly = new DrawablePolygon(coords); negatedBoundMap.Draw(poly); progressCounter++; int percent = 100 * progressCounter / m_bounds.Count(); MainForm.ProgressUpdate(percent); } boundMap.Composite(negatedBoundMap, 0, 0, CompositeOperator.DstOut); } } MainForm.ProgressStartMarquee("Merging ..."); if (ExcludeFromMap) { map.Composite(boundMap, 0, 0, CompositeOperator.DstOut); } else { if (m_transparency != 0) { boundMap.Alpha(AlphaOption.Set); double divideValue = 100.0 / (100.0 - m_transparency); boundMap.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue); } map.Composite(boundMap, 0, 0, CompositeOperator.SrcOver); } } if (debug) { DebugMaps(); } MainForm.ProgressReset(); }
private void DebugMaps() { MainForm.Log("Drawing debug bound images ...", MainForm.LogLevel.warning); MainForm.ProgressStartMarquee("Debug bound images ..."); DirectoryInfo debugDir = new DirectoryInfo(string.Format("{0}\\debug\\bound\\{1}", System.Windows.Forms.Application.StartupPath, zoneConfiguration.ZoneId)); if (!debugDir.Exists) { debugDir.Create(); } debugDir.GetFiles().ToList().ForEach(f => f.Delete()); int boundIndex = 0; foreach (List <PointF> allCoords in m_bounds) { using (MagickImage bound = new MagickImage(MagickColors.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { List <PointD> coords = allCoords.Select(c => new PointD(zoneConfiguration.ZoneCoordinateToMapCoordinate(c.X), zoneConfiguration.ZoneCoordinateToMapCoordinate(c.Y))).ToList(); DrawablePolygon poly = new DrawablePolygon(coords); bound.Settings.FillColor = new MagickColor(0, 0, 0, 256 * 128); bound.Draw(poly); // Print Text for (int i = 0; i < coords.Count; i++) { double x, y; if (coords[i].X > zoneConfiguration.TargetMapSize / 2) { x = coords[i].X - 15; } else { x = coords[i].X + 1; } if (coords[i].Y < zoneConfiguration.TargetMapSize / 2) { y = coords[i].Y + 15; } else { y = coords[i].Y - 1; } bound.Settings.FontPointsize = 10.0; bound.Settings.FillColor = Color.Black; DrawableText text = new DrawableText(x, y, string.Format("{0} ({1}/{2})", i, zoneConfiguration.MapCoordinateToZoneCoordinate(coords[i].X), zoneConfiguration.MapCoordinateToZoneCoordinate(coords[i].Y))); bound.Draw(text); using (IPixelCollection pixels = bound.GetPixels()) { int x2, y2; if (coords[i].X == zoneConfiguration.TargetMapSize) { x2 = zoneConfiguration.TargetMapSize - 1; } else { x2 = (int)coords[i].X; } if (coords[i].Y == zoneConfiguration.TargetMapSize) { y2 = zoneConfiguration.TargetMapSize - 1; } else { y2 = (int)coords[i].Y; } pixels.SetPixel(x2, y2, new ushort[] { 0, 0, 65535, 0 }); } } //bound.Quality = 100; bound.Write(string.Format("{0}\\bound_{1}.png", debugDir.FullName, boundIndex)); boundIndex++; } } MainForm.ProgressReset(); }
public void Test_Drawables() { Coordinate[] coordinates = new Coordinate[3]; coordinates[0] = new Coordinate(0, 0); coordinates[1] = new Coordinate(50, 50); coordinates[2] = new Coordinate(99, 99); using (MagickImage image = new MagickImage(MagickColor.Transparent, 100, 100)) { image.Draw(new DrawableAffine(0, 0, 1, 1, 2, 2)); image.Draw(new DrawableArc(0, 0, 10, 10, 45, 90)); image.Draw(new DrawableBezier(coordinates)); image.Draw(new DrawableCircle(0, 0, 50, 50)); image.Draw(new DrawableClipPath("foo")); image.Draw(new DrawableColor(0, 0, PaintMethod.Floodfill)); using (MagickImage compositeImage = new MagickImage(new MagickColor("red"), 50, 50)) { image.Draw(new DrawableCompositeImage(0, 0, compositeImage)); image.Draw(new DrawableCompositeImage(0, 0, CompositeOperator.Over, compositeImage)); image.Draw(new DrawableCompositeImage(new MagickGeometry(50, 50, 10, 10), compositeImage)); image.Draw(new DrawableCompositeImage(new MagickGeometry(50, 50, 10, 10), CompositeOperator.Over, compositeImage)); } image.Draw(new DrawableDashArray(new double[2] { 10, 20 })); image.Draw(new DrawableDashOffset(2)); image.Draw(new DrawableDensity(97)); image.Draw(new DrawableEllipse(10, 10, 4, 4, 0, 360)); image.Draw(new DrawableFillOpacity(new Percentage(50))); image.Draw(new DrawableFillColor(Color.Red)); image.Draw(new DrawableFont("Arial")); image.Draw(new DrawableGravity(Gravity.Center)); image.Draw(new DrawableLine(20, 20, 40, 40)); image.Draw(new DrawableMiterLimit(5)); image.Draw(new DrawableOpacity(0, 0, PaintMethod.Floodfill)); image.Draw(new DrawablePoint(60, 60)); image.Draw(new DrawablePointSize(5)); image.Draw(new DrawablePolygon(coordinates)); image.Draw(new DrawablePolyline(coordinates)); image.Draw(new DrawableRectangle(30, 30, 70, 70)); image.Draw(new DrawableRotation(180)); image.Draw(new DrawableRoundRectangle(50, 50, 30, 30, 70, 70)); image.Draw(new DrawableScaling(15, 15)); image.Draw(new DrawableSkewX(90)); image.Draw(new DrawableSkewY(90)); image.Draw(new DrawableStrokeAntialias(true)); image.Draw(new DrawableStrokeColor(Color.Purple)); image.Draw(new DrawableStrokeLineCap(LineCap.Square)); image.Draw(new DrawableStrokeLineJoin(LineJoin.Bevel)); image.Draw(new DrawableStrokeOpacity(new Percentage(80))); image.Draw(new DrawableStrokeWidth(4)); image.Draw(new DrawableText(0, 60, "test")); image.Draw(new DrawableTextAntialias(true)); image.Draw(new DrawableTextDecoration(TextDecoration.LineThrough)); image.Draw(new DrawableTextDirection(TextDirection.RightToLeft)); image.Draw(new DrawableTextInterlineSpacing(4)); image.Draw(new DrawableTextInterwordSpacing(6)); image.Draw(new DrawableTextKerning(2)); image.Draw(new DrawableTextUnderColor(Color.Yellow)); image.Draw(new DrawableTranslation(65, 65)); image.Draw(new DrawableViewbox(0, 0, 100, 100)); image.Draw(new DrawablePushClipPath("#1"), new DrawablePopClipPath()); image.Draw(new DrawablePushPattern("test", 30, 30, 10, 10), new DrawablePopPattern()); image.Draw(new DrawablePushGraphicContext(), new DrawablePopGraphicContext()); } }
public IActionResult Index(PosterModel model) { string originalImage = Path.Combine(webrootPath, "images", "large_Event_Poster_Pasta.png"); string newFilePath = Path.Combine(webrootPath, "images", "poster_with_data.png"); string pdffile = Path.Combine(webrootPath, "images", "poster_with_data.pdf"); string font = Path.Combine(webrootPath, "fonts", "TGSharpSans-Medium.ttf"); string extraBoldFont = Path.Combine(webrootPath, "fonts", "TGSharpSans-Semibold.ttf"); string thinFont = Path.Combine(webrootPath, "fonts", "TGSharpSans-Thin.ttf"); using (MagickImage image = new MagickImage(originalImage)) { // image.Draw(drawables); var readSettings = new MagickReadSettings { FillColor = MagickColors.Black, BackgroundColor = MagickColors.Transparent, // TextGravity = Gravity.Center, Width = 400, StrokeColor = MagickColors.Black, Font = extraBoldFont, FontPointsize = 36, }; using (var caption = new MagickImage($"caption: {model.EventName.Replace('~','\n').ToUpper()}", readSettings)) { image.Composite(caption, 100, 500, CompositeOperator.Over); } readSettings.Font = font; using (var caption = new MagickImage($"caption: {model.EventDate.Replace('~', '\n').ToUpper()}", readSettings)) { image.Composite(caption, 100, 600, CompositeOperator.Over); } readSettings.FontPointsize = 18; using (var caption = new MagickImage($"caption: {model.Location.Replace('~', '\n').ToUpper()}", readSettings)) { image.Composite(caption, 100, 650, CompositeOperator.Over); } DrawableLine line = new DrawableLine(100, 700, 600, 700); image.Draw(line); readSettings.FontPointsize = 14; readSettings.Width = 200; readSettings.Font = thinFont; using (var caption = new MagickImage($"caption: {model.Explanation}", readSettings)) { image.Composite(caption, 100, 725, CompositeOperator.Over); } using (var caption = new MagickImage($"caption: {model.AdditionalDetails}", readSettings)) { image.Composite(caption, 400, 725, CompositeOperator.Over); } //var eventNameDrawable = new Drawables() // .Font(@"H:\publicH\Downloads\TenderGreensSharpSans-Extrabold.woff2",FontStyleType.Bold,FontWeight.Bold, FontStretch.Normal) // .FontPointSize(72) // .StrokeColor(MagickColors.Black) // .Text(100,600, model.EventName.ToUpper()) // .Draw(image); //var drawable = new Drawables() // //.FontPointSize(72) // //.Font(extraBoldFont) // //.StrokeColor(MagickColors.Black) // //.TextAlignment(TextAlignment.Left) // // .Text(100, 600, model.EventName.ToUpper()) // .FontPointSize(36) // .Font(font) // .StrokeColor(MagickColors.Black) // .TextAlignment(TextAlignment.Left) // .Text(100, 700, model.EventDate.ToUpper()) // .Text(100, 800, model.Location.ToUpper()) // //.StrokeColor(new MagickColor(0, Quantum.Max, 0)) // //.FillColor(MagickColors.SaddleBrown) // //.Ellipse(256, 96, 192, 8, 0, 360) // .Draw(image); image.Write(newFilePath); model.ImageSrc = "/images/poster_with_data.png"; image.Write(pdffile); //ExifProfile profile = image.GetExifProfile(); //if (profile == null) { // ViewData["Message"] = "Image does not contain exif information"; //} //else { // string message = ""; // foreach (ExifValue value in profile.Values) { // message += $"{value.Tag} ({value.DataType}): {value.ToString()}<br />"; // } //} } return(View(model)); }
public void Test_Drawables_Exceptions() { ExceptionAssert.Throws <ArgumentException>(delegate() { new DrawableBezier(); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableBezier(null); }); ExceptionAssert.Throws <ArgumentException>(delegate() { new DrawableBezier(new PointD[] { }); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableClipPath(null); }); ExceptionAssert.Throws <ArgumentException>(delegate() { new DrawableClipPath(""); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableComposite(null, new MagickImage(Files.Builtin.Logo)); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableComposite(new MagickGeometry(), null); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableFillColor(null); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableFont(null); }); ExceptionAssert.Throws <ArgumentException>(delegate() { new DrawableFont(""); }); ExceptionAssert.Throws <MagickDrawErrorException>(delegate() { using (IMagickImage image = new MagickImage(Files.Builtin.Wizard)) { image.Draw(new DrawableFillPatternUrl("#fail")); } }); ExceptionAssert.Throws <ArgumentException>(delegate() { new DrawablePolygon(new PointD[] { new PointD(0, 0) }); }); ExceptionAssert.Throws <ArgumentException>(delegate() { new DrawablePolyline(new PointD[] { new PointD(0, 0), new PointD(0, 0) }); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableStrokeColor(null); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableText(0, 0, null); }); ExceptionAssert.Throws <ArgumentException>(delegate() { new DrawableText(0, 0, ""); }); ExceptionAssert.Throws <ArgumentNullException>(delegate() { new DrawableTextEncoding(null); }); }
public void MakeCards() { var deck = JsonConvert.DeserializeObject <Deck>(File.ReadAllText(@"C:\temp\testdeck.cm")); var cards = new List <MagickImage>(); foreach (var card in deck.Cards) { var image = new MagickImage(new MagickColor("WhiteSmoke"), deck.Width, deck.Height); image.Density = new MagickGeometry(300, 300); image.Format = MagickFormat.Bmp; foreach (var element in deck.Elements) { var data = card.ElementData[element.Key]; if (File.Exists(data)) { using (var overlayImage = new MagickImage(data)) { image.Composite(overlayImage, (int)element.Value.X, (int)element.Value.Y, CompositeOperator.Over); } } else { using (var textImage = new MagickImage(MagickColor.Transparent, deck.Width, deck.Height)) { textImage.Density = new MagickGeometry(300, 300); textImage.Font = "Arial"; textImage.FontPointsize = 12; textImage.FillColor = new MagickColor("Black"); var drawableText = new DrawableText(element.Value.X, element.Value.Y, data); textImage.Draw(drawableText); image.Composite(textImage, CompositeOperator.Over); } } } image.Write(string.Format(@"c:\temp\CardMaker\{0}.png", card.Name)); cards.Add(image); } using (var doc = new Document()) { PdfWriter.GetInstance(doc, new FileStream(@"C:\temp\CardMaker\cards.pdf", FileMode.Create)); doc.Open(); var columns = (int)Math.Floor(doc.PageSize.Width / (deck.Width + 10)); var table = new PdfPTable(columns) { WidthPercentage = 100, DefaultCell = { Border = 0, Padding = 5 } }; foreach (var card in cards) { var instance = Image.GetInstance(card.ToByteArray()); instance.SetDpi(300, 300); var cell = new PdfPCell(instance) { HorizontalAlignment = Element.ALIGN_CENTER, Border = 0, Padding = 5, }; table.AddCell(cell); } table.CompleteRow(); doc.Add(table); } }
public void Test_Drawable() { using (MagickImage image = new MagickImage(Color.Red, 10, 10)) { MagickColor yellow = Color.Yellow; image.Draw(new DrawableFillColor(yellow), new DrawableRectangle(0, 0, 10, 10)); Test_Pixel(image, 5, 5, yellow); } }