public void Render(DrawingArea area, SettingsModel settings) { var width = area.Allocation.Width; var height = area.Allocation.Height; var kaleidoscope = _factory.Get (settings.Type); var rootNode = kaleidoscope.Generate ( settings.GeometyWidth, settings.ImageUri, width, height); ImageSurface surface = new ImageSurface(Format.Argb32, width, height); using (var context = new Context (surface)) { context.Translate(width / 2, height / 2); rootNode.Render (context); } rootNode.Geometry.Dispose (); using (Context context = Gdk.CairoHelper.Create (area.GdkWindow)) { context.Rectangle(0, 0, width, height); context.SetSource(surface); context.Fill(); context.GetTarget ().Dispose (); } surface.Dispose (); }
protected void OnBtnConvertClicked(object sender, EventArgs e) { var pdfRectangles = new Dictionary<string, Dictionary<int, List<Tuple<Exameer.Rectangle, string>>> > (); // Merge rectangles foreach (PdfNode pdf in StorePDF) { foreach (var png in pdf.Images) { foreach (var rectangle in png.Rectangles) { if (pdfRectangles.ContainsKey (pdf.Name)) { if (pdfRectangles [pdf.Name].ContainsKey (rectangle.ID)) { pdfRectangles [pdf.Name] [rectangle.ID].Add (new Tuple<Exameer.Rectangle, string> (rectangle, png.FileName)); } else { pdfRectangles [pdf.Name].Add (rectangle.ID, new List<Tuple<Exameer.Rectangle, string>> () { new Tuple<Exameer.Rectangle, string>(rectangle, png.FileName) } ); } } else { pdfRectangles.Add (pdf.Name, new Dictionary<int, List<Tuple<Exameer.Rectangle, string>>> () {{ rectangle.ID, new List<Tuple<Exameer.Rectangle, string>>() { new Tuple<Exameer.Rectangle, string>(rectangle, png.FileName) }}} ); } } } } int problemNbr = 0; foreach (var pdf in pdfRectangles) { var createdDestinationDir = Directory.CreateDirectory ("./" + pdf.Key.Replace (".pdf", "") + "/"); foreach (var pngrects in pdf.Value) { var surfaces = new List<Tuple<ImageSurface, Exameer.Rectangle>> (); foreach (var rectangle in pngrects.Value) { surfaces.Add (new Tuple<ImageSurface, Exameer.Rectangle> (new ImageSurface (rectangle.Item2), rectangle.Item1)); } var png = new ImageSurface (pngrects.Value [0].Item2); var rectsMaxWidth = pngrects.Value.Max (x => x.Item1.Width); var rectsMaxHeight = pngrects.Value.Select (x => x.Item1.Height).Sum (); var newRectWidth = (int)((rectsMaxWidth / (float)pngrects.Value [0].Item1.Parent.Width) * png.Width); var newRectHeight = (int)((rectsMaxHeight / (float)pngrects.Value [0].Item1.Parent.Height) * png.Height); //pngrects.Value.Aggregate(0, (sum, next) => sum + next.Item1.Height); ImageSurface newImg = new ImageSurface (Format.Argb32, newRectWidth, newRectHeight); Context cr = new Context (newImg); //cr.SetSourceRGBA (1, 1, 1, 1); //cr.Paint (); // Assume they are sorted by their appearance in PNGs. int lastY = 0; foreach (var surface in surfaces) { var dstx = 0; var dsty = lastY; var r = surface.Item2; var srcx = (int)((r.x1 / (float)r.Parent.Width) * png.Width); var srcy = ((int)((r.y1 / (float)r.Parent.Height) * png.Height)); var w = (int)((r.Width / (float)r.Parent.Width) * png.Width); var h = (int)((r.Height / (float)r.Parent.Height) * png.Height); cr.SetSourceSurface (surface.Item1, dstx - srcx, dsty - srcy); cr.Rectangle (dstx, dsty, w, h); cr.Fill (); //lastY = (int)((r.Height / (float)r.Parent.Height) * png.Height); lastY = dsty + h; } newImg.Flush (); newImg.WriteToPng ("./" + pdf.Key.Replace (".pdf", "") + "/" + (problemNbr++) + ".png"); newImg.Dispose (); //newImg.Dispose (); //surfaces.ForEach (x => x.Item1.Destroy ()); surfaces.ForEach (x => x.Item1.Dispose ()); png.Dispose (); //png.Destroy (); } problemNbr = 0; } }
ImageInfo CreateBlur(ImageInfo source) { double scale = Math.Max (256 / (double)source.Bounds.Width, 256 / (double)source.Bounds.Height); var small = new Gdk.Rectangle (0, 0, (int)Math.Ceiling (source.Bounds.Width * scale), (int)Math.Ceiling (source.Bounds.Height * scale)); var image = new ImageSurface (Format.Argb32, small.Width, small.Height); var ctx = new Context (image); ctx.Matrix = source.Fit (small); ctx.Operator = Operator.Source; Pattern p = new SurfacePattern (source.Surface); ctx.SetSource (p); ctx.Paint (); p.Dispose (); ctx.Dispose (); ImageInfo overlay = null; using (var normal = image.ToPixbuf ()) { using (var pixbufBlur = PixbufUtils.Blur (normal, 3, null)) { overlay = new ImageInfo (pixbufBlur); } } image.Dispose (); return overlay; }
private void imageToolStripMenuItem_Click(object sender, EventArgs e) { lastSelected = "image"; OnPaintAction = cr => { int w, h; ImageSurface image; image = new ImageSurface(romedalenPngData); w = image.Width; h = image.Height; cr.Translate(128.0, 128.0); cr.Rotate(45 * Math.PI / 180); cr.Scale(256.0 / w, 256.0 / h); cr.Translate(-0.5 * w, -0.5 * h); cr.SetSource(image, 0, 0); cr.Paint(); image.Dispose(); }; Invalidate(); }
private void imagepatternToolStripMenuItem_Click(object sender, EventArgs e) { lastSelected = "imagepattern"; OnPaintAction = cr => { int w, h; ImageSurface image; Pattern pattern; Matrix matrix = new Matrix(); image = new ImageSurface(romedalenPngData); w = image.Width; h = image.Height; pattern = new SurfacePattern(image); pattern.Extend = Extend.Repeat; cr.Translate(128.0, 128.0); cr.Rotate(Math.PI / 4); cr.Scale(1 / Math.Sqrt(2), 1 / Math.Sqrt(2)); cr.Translate(-128.0, -128.0); matrix.InitScale(w/256.0*5.0, h/256.0*5.0); pattern.Matrix = matrix; cr.SetSource(pattern); cr.Rectangle(0, 0, 256.0, 256.0); cr.Fill(); pattern.Dispose(); image.Dispose(); }; Invalidate(); }
private void clipImageToolStripMenuItem_Click(object sender, EventArgs e) { lastSelected = "clipImage"; OnPaintAction = cr => { int w, h; ImageSurface image; cr.Arc(128.0, 128.0, 76.8, 0, 2 * Math.PI); cr.Clip(); cr.NewPath(); /* path not consumed by clip()*/ image = new ImageSurface(romedalenPngData); w = image.Width; h = image.Height; cr.Scale(256.0 / w, 256.0 / h); cr.SetSource(image, 0, 0); cr.Paint(); image.Dispose(); }; Invalidate(); }
private Pattern RenderBar (int w, int h) { ImageSurface s = new ImageSurface (Format.Argb32, w, h); Context cr = new Context (s); RenderBar (cr, w, h, h / 2); // TODO Implement the new ctor - see http://bugzilla.gnome.org/show_bug.cgi?id=561394 #pragma warning disable 0618 Pattern pattern = new Pattern (s); #pragma warning restore 0618 s.Dispose (); ((IDisposable)cr).Dispose (); return pattern; }