public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { this.radius = Data.Radius; foreach (Gdk.Rectangle rect in rois) RenderRectWithAlpha (this.radius, src, dest, rect); }
public static SurfacePattern CreateTileBrush(TileBrush brush, Size targetSize) { var helper = new TileBrushImplHelper(brush, targetSize); if (!helper.IsValid) return null; using (var intermediate = new ImageSurface(Format.ARGB32, (int)helper.IntermediateSize.Width, (int)helper.IntermediateSize.Height)) using (var ctx = new RenderTarget(intermediate).CreateDrawingContext()) { helper.DrawIntermediate(ctx); var result = new SurfacePattern(intermediate); if ((brush.TileMode & TileMode.FlipXY) != 0) { // TODO: Currently always FlipXY as that's all cairo supports natively. // Support separate FlipX and FlipY by drawing flipped images to intermediate // surface. result.Extend = Extend.Reflect; } else { result.Extend = Extend.Repeat; } if (brush.TileMode != TileMode.None) { var matrix = result.Matrix; matrix.InitTranslate(-helper.DestinationRect.X, -helper.DestinationRect.Y); result.Matrix = matrix; } return result; } }
static void Main() { // The using statement ensures that potentially heavy objects // are disposed immediately. using (ImageSurface draw = new ImageSurface(Format.Argb32, 70, 150)) { using (Context gr = new Context(draw)) { gr.Antialias = Antialias.Subpixel; // sets the anti-aliasing method gr.LineWidth = 9; // sets the line width gr.SetSourceColor(new Color(0, 0, 0, 1)); // red, green, blue, alpha gr.MoveTo(10, 10); // sets the Context's start point. gr.LineTo(40, 60); // draws a "virtual" line from 5,5 to 20,30 gr.Stroke(); //stroke the line to the image surface gr.Antialias = Antialias.Gray; gr.LineWidth = 8; gr.SetSourceColor(new Color(1, 0, 0, 1)); gr.LineCap = LineCap.Round; gr.MoveTo(10, 50); gr.LineTo(40, 100); gr.Stroke(); gr.Antialias = Antialias.None; //fastest method but low quality gr.LineWidth = 7; gr.MoveTo(10, 90); gr.LineTo(40, 140); gr.Stroke(); draw.WriteToPng("antialias.png"); //save the image as a png image. } } }
public GtkGraphDrawer(Context g, Context gh, ImageSurface srfc) { this.g = g; this.gh = gh; this.srfc = srfc; gh.Antialias = Antialias.Subpixel; }
/// <summary> /// A history item for when shapes are finalized. /// </summary> /// <param name="passedEE">The EditEngine being used.</param> /// <param name="icon">The history item's icon.</param> /// <param name="text">The history item's title.</param> /// <param name="passedUserSurface">The stored UserLayer surface.</param> /// <param name="passedUserLayer">The UserLayer being modified.</param> /// <param name="passedSelectedPointIndex">The selected point's index.</param> /// <param name="passedSelectedShapeIndex">The selected point's shape index.</param> /// <param name="passedRedrawEverything">Whether every shape should be redrawn when undoing (e.g. finalization).</param> public ShapesHistoryItem(BaseEditEngine passedEE, string icon, string text, ImageSurface passedUserSurface, UserLayer passedUserLayer, int passedSelectedPointIndex, int passedSelectedShapeIndex, bool passedRedrawEverything) : base(icon, text) { ee = passedEE; userLayer = passedUserLayer; userSurfaceDiff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true); if (userSurfaceDiff == null) { userSurface = passedUserSurface; } else { (passedUserSurface as IDisposable).Dispose(); } sEngines = BaseEditEngine.SEngines.PartialClone(); selectedPointIndex = passedSelectedPointIndex; selectedShapeIndex = passedSelectedShapeIndex; redrawEverything = passedRedrawEverything; }
public static ImageSurface Create (Gdk.Pixbuf pixbuf, bool disposePixbuf) { if (pixbuf == null || pixbuf.Handle == IntPtr.Zero) { return null; } if (!PlatformDetection.IsWindows) { try { return new PixbufImageSurface (pixbuf, disposePixbuf); } catch { return null; } } else { // FIXME: // Windows has some trouble running the PixbufImageSurface, so as a // workaround a slower but working version of this factory method is // implemented. One day we can come back and optimize this by finding // out what's causing the PixbufImageSurface to result in access // violations when the object is disposed. ImageSurface target = new ImageSurface (Format.ARGB32, pixbuf.Width, pixbuf.Height); Context context = new Context (target); try { Gdk.CairoHelper.SetSourcePixbuf (context, pixbuf, 0, 0); context.Paint (); } finally { ((IDisposable)context).Dispose (); if (disposePixbuf) { ((IDisposable)pixbuf).Dispose (); } } return target; } }
public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { bacAdjustment.Data.Brightness = -Data.ColorRange; bacAdjustment.Data.Contrast = -Data.ColorRange; bacAdjustment.Render (src, dest, rois); blurEffect.Data.Radius = Data.PencilTipSize; blurEffect.Render (src, dest, rois); invertEffect.Render (dest, dest, rois); desaturateOp.Apply (dest, dest, rois); ColorBgra* dst_dataptr = (ColorBgra*)dest.DataPtr; int dst_width = dest.Width; ColorBgra* src_dataptr = (ColorBgra*)src.DataPtr; int src_width = src.Width; foreach (Gdk.Rectangle roi in rois) { for (int y = roi.Top; y <= roi.GetBottom (); ++y) { ColorBgra* srcPtr = src.GetPointAddressUnchecked (src_dataptr, src_width, roi.X, y); ColorBgra* dstPtr = dest.GetPointAddressUnchecked (dst_dataptr, dst_width, roi.X, y); for (int x = roi.Left; x <= roi.GetRight (); ++x) { ColorBgra srcGrey = desaturateOp.Apply (*srcPtr); ColorBgra sketched = colorDodgeOp.Apply (srcGrey, *dstPtr); *dstPtr = sketched; ++srcPtr; ++dstPtr; } } } }
private unsafe void ApplyRectangle (ImageSurface surface, Gdk.Rectangle rect) { for (int y = rect.Left; y <= rect.GetBottom (); ++y) { ColorBgra* ptr = surface.GetPointAddress (rect.Left, y); Apply (ptr, rect.Width); } }
public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { int warmth = Data.Warmth; float redAdjust = 1.0f + (warmth / 100.0f); float blueAdjust = 1.0f - (warmth / 100.0f); this.blurEffect.Render(src, dest, rois); this.bacAdjustment.Render(src, dest, rois); foreach (Gdk.Rectangle roi in rois) { for (int y = roi.Top; y <= roi.GetBottom (); ++y) { ColorBgra* srcPtr = src.GetPointAddress(roi.X, y); ColorBgra* dstPtr = dest.GetPointAddress(roi.X, y); for (int x = roi.Left; x <= roi.GetRight (); ++x) { ColorBgra srcGrey = this.desaturateOp.Apply(*srcPtr); srcGrey.R = Utility.ClampToByte((int)((float)srcGrey.R * redAdjust)); srcGrey.B = Utility.ClampToByte((int)((float)srcGrey.B * blueAdjust)); ColorBgra mypixel = this.overlayOp.Apply(srcGrey, *dstPtr); *dstPtr = mypixel; ++srcPtr; ++dstPtr; } } } }
public static void RenderThumbnail (Cairo.Context cr, ImageSurface image, bool dispose, double x, double y, double width, double height, bool drawBorder, double radius, bool fill, Color fillColor) { RenderThumbnail (cr, image, dispose, x, y, width, height, drawBorder, radius, fill, fillColor, CairoCorners.All); }
public override void Paint(Cairo.Context gr, Rectangle rect, string subPart = "") { float widthRatio = 1f; float heightRatio = 1f; if (Scaled){ widthRatio = (float)rect.Width / Dimensions.Width; heightRatio = (float)rect.Height / Dimensions.Height; } if (KeepProportions) { if (widthRatio < heightRatio) heightRatio = widthRatio; else widthRatio = heightRatio; } gr.Save (); gr.Translate (rect.Left,rect.Top); gr.Scale (widthRatio, heightRatio); gr.Translate ((rect.Width/widthRatio - Dimensions.Width)/2, (rect.Height/heightRatio - Dimensions.Height)/2); using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32, Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) { gr.SetSourceSurface (imgSurf, 0,0); gr.Paint (); } gr.Restore (); }
/// <summary> /// A history item for when text is created, edited, and/or finalized. /// </summary> /// <param name="icon">The history item's icon.</param> /// <param name="text">The history item's title.</param> /// <param name="passedTextSurface">The stored TextLayer surface.</param> /// <param name="passedUserSurface">The stored UserLayer surface.</param> /// <param name="passedTextEngine">The text engine being used.</param> /// <param name="passedUserLayer">The UserLayer being modified.</param> public TextHistoryItem(string icon, string text, ImageSurface passedTextSurface, ImageSurface passedUserSurface, TextEngine passedTextEngine, UserLayer passedUserLayer) : base(icon, text) { userLayer = passedUserLayer; text_surface_diff = SurfaceDiff.Create(passedTextSurface, userLayer.TextLayer.Layer.Surface, true); if (text_surface_diff == null) { textSurface = passedTextSurface; } else { (passedTextSurface as IDisposable).Dispose(); } user_surface_diff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true); if (user_surface_diff == null) { userSurface = passedUserSurface; } else { (passedUserSurface as IDisposable).Dispose(); } tEngine = passedTextEngine; textBounds = new Gdk.Rectangle(userLayer.textBounds.X, userLayer.textBounds.Y, userLayer.textBounds.Width, userLayer.textBounds.Height); }
public Size ImageSize(string file) { ImageSurface image = new ImageSurface (file); Size result = new Size (image.Width, image.Height); (image as IDisposable).Dispose (); return result; }
protected override Gdk.Rectangle OnMouseMove (Context g, Color strokeColor, ImageSurface surface, int x, int y, int lastX, int lastY) { // Cairo does not support a single-pixel-long single-pixel-wide line if (x == lastX && y == lastY && g.LineWidth == 1 && PintaCore.Workspace.ActiveWorkspace.PointInCanvas (new PointD(x,y))) { surface.Flush (); ColorBgra source = surface.GetColorBgraUnchecked (x, y); source = UserBlendOps.NormalBlendOp.ApplyStatic (source, strokeColor.ToColorBgra ()); surface.SetColorBgra (source, x, y); surface.MarkDirty (); return new Gdk.Rectangle (x - 1, y - 1, 3, 3); } g.MoveTo (lastX + 0.5, lastY + 0.5); g.LineTo (x + 0.5, y + 0.5); g.StrokePreserve (); Gdk.Rectangle dirty = g.FixedStrokeExtents ().ToGdkRectangle (); // For some reason (?!) we need to inflate the dirty // rectangle for small brush widths in zoomed images dirty.Inflate (1, 1); return dirty; }
public unsafe override void Render(ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { var cellSize = Data.CellSize; Gdk.Rectangle src_bounds = src.GetBounds (); Gdk.Rectangle dest_bounds = dest.GetBounds (); foreach (var rect in rois) { for (int y = rect.Top; y <= rect.GetBottom (); ++y) { int yEnd = y + 1; for (int x = rect.Left; x <= rect.GetRight (); ++x) { var cellRect = GetCellBox (x, y, cellSize); cellRect.Intersect (dest_bounds); var color = ComputeCellColor (x, y, src, cellSize, src_bounds); int xEnd = Math.Min (rect.GetRight (), cellRect.GetRight ()); yEnd = Math.Min (rect.GetBottom (), cellRect.GetBottom ()); for (int y2 = y; y2 <= yEnd; ++y2) { ColorBgra* ptr = dest.GetPointAddressUnchecked (x, y2); for (int x2 = x; x2 <= xEnd; ++x2) { ptr->Bgra = color.Bgra; ++ptr; } } x = xEnd; } y = yEnd; } } }
public static SurfacePattern CreateImageBrush(ImageBrush brush, Size targetSize) { if (brush.Source == null) { return null; } // TODO: This is directly ported from Direct2D and could probably be made more // efficient on cairo by taking advantage of the fact that cairo has Extend.None. var image = ((BitmapImpl)brush.Source.PlatformImpl).Surface; var imageSize = new Size(brush.Source.PixelWidth, brush.Source.PixelHeight); var tileMode = brush.TileMode; var sourceRect = brush.SourceRect.ToPixels(imageSize); var destinationRect = brush.DestinationRect.ToPixels(targetSize); var scale = brush.Stretch.CalculateScaling(destinationRect.Size, sourceRect.Size); var translate = CalculateTranslate(brush, sourceRect, destinationRect, scale); var intermediateSize = CalculateIntermediateSize(tileMode, targetSize, destinationRect.Size); var intermediate = new ImageSurface (Format.ARGB32, (int)intermediateSize.Width, (int)intermediateSize.Height); using (var context = new Context(intermediate)) { Rect drawRect; var transform = CalculateIntermediateTransform( tileMode, sourceRect, destinationRect, scale, translate, out drawRect); context.Rectangle(drawRect.ToCairo()); context.Clip(); context.Transform(transform.ToCairo()); Gdk.CairoHelper.SetSourcePixbuf(context, image, 0, 0); context.Rectangle(0, 0, imageSize.Width, imageSize.Height); context.Fill(); var result = new SurfacePattern(intermediate); if ((brush.TileMode & TileMode.FlipXY) != 0) { // TODO: Currently always FlipXY as that's all cairo supports natively. // Support separate FlipX and FlipY by drawing flipped images to intermediate // surface. result.Extend = Extend.Reflect; } else { result.Extend = Extend.Repeat; } if (brush.TileMode != TileMode.None) { var matrix = result.Matrix; matrix.InitTranslate(-destinationRect.X, -destinationRect.Y); result.Matrix = matrix; } return result; } }
private void Form1_Shown(object sender, EventArgs e) { Debug.WriteLine("Form1_Shown"); Win32Surface = new Win32Surface(this.CreateGraphics().GetHdc()); FontContext = new Context(Win32Surface); //CRITICAL: Format of Win32Surface and ImageSurface must be identical! ImageSurface = new ImageSurface(Format.Rgb24, ClientSize.Width, ClientSize.Height); BackContext = new Context(ImageSurface); //Clear Surface2 BackContext.SetSourceColor(new Color(1,1,1)); BackContext.Operator = Operator.Source; BackContext.Paint(); BackContext.Operator = Operator.Over; var textFormat = DWriteCairo.CreateTextFormat( "Arial", FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 32f); Debug.Assert(Math.Abs(textFormat.FontSize - 32f) < 0.0001); const string s = "Hello World"; textLayout = DWriteCairo.CreateTextLayout(s, textFormat, 300, 40); }
unsafe public override void Render (ImageSurface src, ImageSurface dst, Gdk.Rectangle[] rois) { const double jr = 0.3125; const double ji = 0.03; int w = dst.Width; int h = dst.Height; double invH = 1.0 / h; double invZoom = 1.0 / Data.Zoom; double invQuality = 1.0 / Data.Quality; double aspect = (double)h / (double)w; int count = Data.Quality * Data.Quality + 1; double invCount = 1.0 / (double)count; double angleTheta = (Data.Angle * Math.PI * 2) / 360.0; ColorBgra* dst_dataptr = (ColorBgra*)dst.DataPtr; int dst_width = dst.Width; foreach (Gdk.Rectangle rect in rois) { for (int y = rect.Top; y <= rect.GetBottom (); y++) { ColorBgra* dstPtr = dst.GetPointAddressUnchecked (dst_dataptr, dst_width, rect.Left, y); for (int x = rect.Left; x <= rect.GetRight (); x++) { int r = 0; int g = 0; int b = 0; int a = 0; for (double i = 0; i < count; i++) { double u = (2.0 * x - w + (i * invCount)) * invH; double v = (2.0 * y - h + ((i * invQuality) % 1)) * invH; double radius = Math.Sqrt ((u * u) + (v * v)); double radiusP = radius; double theta = Math.Atan2 (v, u); double thetaP = theta + angleTheta; double uP = radiusP * Math.Cos (thetaP); double vP = radiusP * Math.Sin (thetaP); double jX = (uP - vP * aspect) * invZoom; double jY = (vP + uP * aspect) * invZoom; double j = Julia (jX, jY, jr, ji); double c = Data.Factor * j; b += Utility.ClampToByte (c - 768); g += Utility.ClampToByte (c - 512); r += Utility.ClampToByte (c - 256); a += Utility.ClampToByte (c - 0); } *dstPtr = ColorBgra.FromBgra (Utility.ClampToByte (b / count), Utility.ClampToByte (g / count), Utility.ClampToByte (r / count), Utility.ClampToByte (a / count)); ++dstPtr; } } } }
private void Image_Loaded(object sender, RoutedEventArgs e) { Image image = (Image)sender; using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height)) { using (Context context = new Context(surface)) { PointD p = new PointD(10.0, 10.0); PointD p2 = new PointD(100.0, 10.0); PointD p3 = new PointD(100.0, 100.0); PointD p4 = new PointD(10.0, 100.0); context.MoveTo(p); context.LineTo(p2); context.LineTo(p3); context.LineTo(p4); context.LineTo(p); context.ClosePath(); context.Fill(); context.MoveTo(140.0, 110.0); context.SetFontSize(32.0); context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0)); context.ShowText("Hello Cairo!"); surface.Flush(); RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width); image.Source = source; } } }
protected override FlowReturn OnTransformIp (Gst.Buffer buf) { if (!buf.IsWritable) return FlowReturn.Error; Cairo.ImageSurface img = new Cairo.ImageSurface (buf.Data, Cairo.Format.Rgb24, width, height, width*4); using (Cairo.Context context = new Cairo.Context (img)) { double dx = (double) ( (buf.Timestamp / Clock.MSecond) % 2180) / 5; context.Save (); context.Scale (width / 640.0, height / 480.0); context.MoveTo (300, 10 + dx); context.LineTo (500 - dx, 400); context.LineWidth = 4.0; context.Color = new Color (0, 0, 1.0); context.Stroke(); context.Restore (); if (lastX != -1 && lastY != -1) { context.Color = new Color (1.0, 0, 0); context.Translate (lastX, lastY); context.Scale (Math.Min (width / 640.0, height / 480.0), Math.Min (width / 640.0, height / 480.0)); context.Arc (0, 0, 10.0, 0.0, 2 * Math.PI); context.Fill(); } } img.Destroy (); return base.OnTransformIp (buf); }
static void draw (Cairo.Context gr, int width, int height) { int w, h; ImageSurface image; gr.Scale (width, height); gr.LineWidth = 0.04; gr.Arc (0.5, 0.5, 0.3, 0, 2*M_PI); gr.Clip (); gr.NewPath (); image = new ImageSurface("data/e.png"); w = image.Width; h = image.Height; gr.Scale (1.0/w, 1.0/h); image.Show (gr, 0, 0); image.Destroy(); gr.Arc (0.5, 0.5, 0.3, 0, 2 * M_PI); gr.Clip (); gr.NewPath (); gr.Rectangle (new PointD (0, 0), 1, 1); gr.Fill (); gr.Color = new Color (0, 1, 0, 1); gr.MoveTo ( new PointD (0, 0) ); gr.LineTo ( new PointD (1, 1) ); gr.MoveTo ( new PointD (1, 0) ); gr.LineTo ( new PointD (0, 1) ); gr.Stroke (); }
public PlainSurfaceItem(int maxWidth, int maxHeight, int widthRequest = 0, int heightRequest = 0, string label = null) { //Console.WriteLine ("PlainSurfaceItem"); _label = label; this._evtBox = new EventBox (); this._draw = new global::Gtk.DrawingArea (); if(widthRequest > 0) { _draw.WidthRequest = widthRequest; } if(heightRequest > 0) { _draw.HeightRequest = heightRequest; } this._evtBox.Add (this._draw); maxWidth = Math.Max (maxWidth, widthRequest); maxHeight = Math.Max (maxHeight, heightRequest); this._height = Math.Max(_draw.Allocation.Height, heightRequest); this._width = Math.Max(_draw.Allocation.Width, widthRequest); this._mode = DisplayMode.Snapshot; this._surface = new ImageSurface(Format.Argb32, maxWidth, maxHeight); this._button = MouseButton.None; this._background = new Color (1.0, 1.0, 1.0); _draw.ExposeEvent += DrawExpose; _evtBox.ButtonPressEvent += DrawButtonPressEvent; _evtBox.ButtonReleaseEvent += DrawButtonReleaseEvent; _evtBox.MotionNotifyEvent += DrawMotionNotifyEvent; }
protected override void OnMouseDown (Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point) { // If we are already drawing, ignore any additional mouse down events if (mouse_button > 0) return; surface_modified = false; undo_surface = PintaCore.Workspace.ActiveDocument.CurrentUserLayer.Surface.Clone (); mouse_button = args.Event.Button; Color tool_color; if (mouse_button == 1) { tool_color = PintaCore.Palette.PrimaryColor; } else if (mouse_button == 3) { tool_color = PintaCore.Palette.SecondaryColor; } else { last_point = point_empty; return; } Draw (canvas, tool_color, point, true); }
public override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { if (op == null) op = new UnaryPixelOps.PosterizePixel (Data.Red, Data.Green, Data.Blue); op.Apply (dest, src, rois); }
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 (); }
public SketchPad(IPuzzleQueryResolver resolver) { ImageSurface imsu = new ImageSurface(Format.Argb32,0x01,0x01); this.subcontext = new Context(imsu); this.AddEvents((int) (Gdk.EventMask.PointerMotionMask|Gdk.EventMask.ButtonPressMask|Gdk.EventMask.ButtonReleaseMask)); this.resolver = resolver; }
public void Dispose () { if (img != null) { img.Dispose (); img = null; } }
public Layer(ImageSurface surface, bool hidden, double opacity, string name) { Surface = surface; Hidden = hidden; Opacity = opacity; Name = name; Offset = new PointD (0, 0); }
public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { this.radius = Data.Radius; this.percentile = Data.Percentile; foreach (Gdk.Rectangle rect in rois) RenderRect (this.radius, src, dest, rect); }
public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { this.radius = Data.Radius; this.strength = -0.2 * Data.Strength; foreach (Gdk.Rectangle rect in rois) RenderRect (this.radius, src, dest, rect); }
private void HandlePintaCoreActionsEditFillSelectionActivated(object sender, EventArgs e) { Document doc = PintaCore.Workspace.ActiveDocument; PintaCore.Tools.Commit(); Cairo.ImageSurface old = doc.CurrentUserLayer.Surface.Clone(); using (var g = new Cairo.Context(doc.CurrentUserLayer.Surface)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSourceColor(PintaCore.Palette.PrimaryColor); g.Fill(); } doc.Workspace.Invalidate(); doc.History.PushNewItem(new SimpleHistoryItem("Menu.Edit.FillSelection.png", Catalog.GetString("Fill Selection"), old, doc.CurrentUserLayerIndex)); }
protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point) { // If we are already drawing, ignore any additional mouse down events if (is_dragging) { return; } Document doc = PintaCore.Workspace.ActiveDocument; origin_offset = point; is_dragging = true; hist = new MovePixelsHistoryItem(Icon, Name, doc); hist.TakeSnapshot(!doc.ShowSelectionLayer); if (!doc.ShowSelectionLayer) { // Copy the selection to the temp layer doc.CreateSelectionLayer(); doc.ShowSelectionLayer = true; using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) { g.AppendPath(doc.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSource(doc.CurrentLayer.Surface); g.Clip(); g.Paint(); } Cairo.ImageSurface surf = doc.CurrentLayer.Surface; using (Cairo.Context g = new Cairo.Context(surf)) { g.AppendPath(doc.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Operator = Cairo.Operator.Clear; g.Fill(); } } canvas.GdkWindow.Invalidate(); }
void DrawOverlay(System.Object o, Gtk.DrawnArgs args) { var imageViewWidget = this.drawingArea as ImageViewWidget; if (imageViewWidget == null || imageViewWidget.Image == null || !this.IsActive || !this.UpdateFade(imageViewWidget)) { return; } this.canvasSize = new Cairo.PointD(this.drawingArea.Allocation.Width, this.drawingArea.Allocation.Height); var image = imageViewWidget.Image; bool redrawOverlay = this.canvasSize.X != this.lastCanvasSize.X || this.canvasSize.Y != this.lastCanvasSize.Y || image != this.lastImage || image.NeedsOverlayRedrawn; if (redrawOverlay) { var overlaySurface = new Cairo.ImageSurface(Cairo.Format.ARGB32, (int)this.canvasSize.X, (int)this.canvasSize.Y); var overlayCr = new Cairo.Context(overlaySurface); this.RedrawOverlay(overlayCr, image); overlayCr.Dispose(); if (this.overlaySurface != null) { this.overlaySurface.Dispose(); } this.overlaySurface = overlaySurface; image.NeedsOverlayRedrawn = false; } args.Cr.SetSourceSurface(this.overlaySurface, 0, 0); args.Cr.PaintWithAlpha(this.currentFadeOpacity); this.lastCanvasSize = this.canvasSize; this.lastImage = image; }
public unsafe static Gdk.Pixbuf ToPixbuf(this Cairo.ImageSurface surfSource) { Cairo.ImageSurface surf = surfSource.Clone(); surf.Flush(); ColorBgra *dstPtr = (ColorBgra *)surf.DataPtr; int len = surf.Data.Length / 4; for (int i = 0; i < len; i++) { if (dstPtr->A != 0) { *dstPtr = (ColorBgra.FromBgra(dstPtr->R, dstPtr->G, dstPtr->B, dstPtr->A)); } dstPtr++; } Gdk.Pixbuf pb = new Gdk.Pixbuf(surf.Data, true, 8, surf.Width, surf.Height, surf.Stride); (surf as IDisposable).Dispose(); return(pb); }
protected override void OnStartTransform() { base.OnStartTransform(); Document doc = PintaCore.Workspace.ActiveDocument; original_selection = new List <List <IntPoint> > (doc.Selection.SelectionPolygons); original_transform.InitMatrix(doc.SelectionLayer.Transform); hist = new MovePixelsHistoryItem(Icon, Name, doc); hist.TakeSnapshot(!doc.ShowSelectionLayer); if (!doc.ShowSelectionLayer) { // Copy the selection to the temp layer doc.CreateSelectionLayer(); doc.ShowSelectionLayer = true; using (Cairo.Context g = new Cairo.Context(doc.SelectionLayer.Surface)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.SetSource(doc.CurrentUserLayer.Surface); g.Clip(); g.Paint(); } Cairo.ImageSurface surf = doc.CurrentUserLayer.Surface; using (Cairo.Context g = new Cairo.Context(surf)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Operator = Cairo.Operator.Clear; g.Fill(); } } PintaCore.Workspace.Invalidate(); }
public void HandleExport(object o, EventArgs ev) { FileChooserDialog chooser = new FileChooserDialog( "Export Handwriting to PNG", null, FileChooserAction.Save); chooser.SetCurrentFolder(Environment.GetFolderPath( Environment.SpecialFolder.Personal)); chooser.AddButton(Gtk.Stock.Cancel, ResponseType.Cancel); chooser.AddButton(Gtk.Stock.Ok, ResponseType.Ok); chooser.DefaultResponse = ResponseType.Ok; if (chooser.Run() == (int)ResponseType.Ok) { string path = (new Uri(chooser.Uri)).AbsolutePath; Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, handwriting.Allocation.Width, handwriting.Allocation.Height); handwriting.DrawToSurface(surface, handwriting.Allocation); Console.WriteLine("PNG saved to {0}", path); surface.WriteToPng(path); } chooser.Destroy(); }
public void GenerateImage() { UnrotatedRect = Parts.getRotationRect(); using (var surf = new Cairo.ImageSurface(Format.ARGB32, UnrotatedRect.Width, UnrotatedRect.Height)) { using (var cr = new Context(surf)) { //Clear if (Debug) { cr.SetSourceColor(new Cairo.Color(0, 0.9, 0)); cr.Rectangle(0, 0, UnrotatedRect.Width, UnrotatedRect.Height); cr.Fill(); } else { cr.Operator = Operator.Clear; cr.Paint(); cr.Operator = Operator.Over; } foreach (var part in Parts) { if (part.Rotate) { //Draw image part.draw(cr); } } if (Debug) { cr.LineWidth = 5; cr.SetSourceRGBA(1, 0, 0, 1); cr.Translate(DebugPoint.X, DebugPoint.Y); cr.Arc(0, 0, 2, 0, Math.PI * 2); cr.StrokePreserve(); } } //surf.WriteToPng ("test.png"); //var angle = 0; var oldRotatedRect = RotatedRect; RotatedRect = Helper.RotateRect(UnrotatedRect, RotationCenterZero, Angle); //Rotate var surf2 = new Cairo.ImageSurface(Format.ARGB32, RotatedRect.Width, RotatedRect.Height); using (var cr = new Context(surf2)) { cr.Operator = Operator.Clear; cr.Paint(); cr.Operator = Operator.Over; cr.Translate(-RotatedRect.X, -RotatedRect.Y); cr.Rotate(Angle); //var pp = funcs.rotatePoint (rotationRect.Location, new POINT (0, 0), angle); using (var pat2 = new SurfacePattern(surf)) { //pat2.Matrix = new Matrix (){ X0 = -rr.X, Y0 = -rr.Y }; cr.SetSource(pat2); //cr.Translate (100, 100); cr.Paint(); } //Debug if (true) { cr.Matrix = new Matrix(); if (DebugText != null) { //cr.Operator=Operator.Source; cr.SetSourceRGBA(0, 1, 0, 1); cr.SelectFontFace("Arial", FontSlant.Normal, FontWeight.Normal); cr.SetFontSize(20); cr.MoveTo(20, 20); cr.ShowText(DebugText); cr.Fill(); } } foreach (var part in Parts) { if (!part.Rotate) { cr.Matrix = new Matrix(); var c = new POINT(PartBottom.Rect.Location.X + DisplayCenterOffset.X, PartBottom.Rect.Location.Y + DisplayCenterOffset.Y); part.Rect.X = c.X; part.Rect.Y = c.Y; var p = ImagePosToRotatedPos(part.Rect.Location); p.X -= part.Rect.Width / 2; p.Y -= part.Rect.Height / 2; //Draw image using (var pat = new SurfacePattern(part.Image)) { pat.Matrix = new Matrix() { X0 = -p.X, Y0 = -p.Y }; //pat.Matrix = pat.Matrix; cr.SetSource(pat); cr.Rectangle(new Cairo.Rectangle(p.X, p.Y, part.Rect.Width, part.Rect.Height)); cr.Fill(); cr.SetSourceRGBA(0, 0, 0, 1); cr.SelectFontFace("Arial", FontSlant.Normal, FontWeight.Normal); cr.SetFontSize(10); cr.MoveTo(p.X + 12, p.Y + 27.2); var text = Distance.ToString(); cr.ShowText(text); var deg = Math.Round(Helper.RadToDeg(Angle)); if (deg % 45 != 0) { cr.MoveTo(p.X + 14, p.Y + 40.2); text = deg.ToString() + "°"; cr.ShowText(text); } cr.Fill(); } } } /* * cr.Matrix = new Matrix (); * var pos = ImagePosToRotatedPos (part2.rect.Location); * //cr.Translate (pos.X, pos.Y); * * cr.SetSourceRGBA (0, 1, 0, 1); * cr.SelectFontFace ("Arial", FontSlant.Normal, FontWeight.Normal); * cr.SetFontSize (10); * cr.MoveTo (pos.X, pos.Y); * cr.ShowText ("aaaa"); * cr.Fill (); */ } //surf2.WriteToPng ("test2.png"); if (Image != null) { Image.Dispose(); } Image = surf2; } }
public static Gdk.Pixbuf GetAsPixbuf(this Cairo.ImageSurface aSurface) { Gdk.Pixbuf px = BasicUtilities.CairoConvertToPixbuf(aSurface); return(px); }
protected override void onDraw(Cairo.Context gr) { base.onDraw(gr); Rectangle cb = new Rectangle(0, 0, designWidth, designHeight); // ClientRectangle; gr.Save(); double z = zoom / 100.0; gr.Scale(z, z); if (drawGrid) { double gridLineWidth = 0.2 / z; double glhw = gridLineWidth / 2.0; int nbLines = cb.Width / gridSpacing; double d = cb.Left + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(d - glhw, cb.Y); gr.LineTo(d - glhw, cb.Bottom); d += gridSpacing; } nbLines = cb.Height / gridSpacing; d = cb.Top + gridSpacing; for (int i = 0; i < nbLines; i++) { gr.MoveTo(cb.X, d - glhw); gr.LineTo(cb.Right, d - glhw); d += gridSpacing; } gr.LineWidth = gridLineWidth; Foreground.SetAsSource(gr, cb); gr.Stroke(); } lock (imlVE.RenderMutex) { using (Cairo.Surface surf = new Cairo.ImageSurface(imlVE.bmp, Cairo.Format.Argb32, imlVE.ClientRectangle.Width, imlVE.ClientRectangle.Height, imlVE.ClientRectangle.Width * 4)) { gr.SetSourceSurface(surf, cb.Left, cb.Top); gr.Paint(); } imlVE.IsDirty = false; } if (Error == null) { gr.SetSourceColor(Color.Black); gr.Rectangle(cb, 1.0 / z); } else { gr.SetSourceColor(Color.LavenderBlush); gr.Rectangle(cb, 2.0 / z); string[] lerrs = Error.ToString().Split('\n'); Point p = cb.Center; p.Y -= lerrs.Length * 20; foreach (string le in lerrs) { drawCenteredTextLine(gr, p, le); p.Y += 20; } } gr.Stroke(); Rectangle hr; if (SelectedItem?.Parent != null) { gr.SelectFontFace(Font.Name, Font.Slant, Font.Wheight); gr.SetFontSize(Font.Size); gr.FontOptions = Interface.FontRenderingOptions; gr.Antialias = Interface.Antialias; GraphicObject g = SelectedItem; hr = g.ScreenCoordinates(g.getSlot()); // Rectangle rIcons = new Rectangle (iconSize); // rIcons.Width *= 4; // rIcons.Top = hr.Bottom; // rIcons.Left = hr.Right - rIcons.Width + iconSize.Width; Rectangle rIcoMove = new Rectangle(hr.BottomRight, iconSize); // Rectangle rIcoStyle = rIcoMove; // rIcoStyle.Left += iconSize.Width + 4; using (Surface mask = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) { using (Context ctx = new Context(mask)) { ctx.Save(); ctx.SetSourceRGBA(1.0, 1.0, 1.0, 0.4); ctx.Paint(); ctx.Rectangle(hr); ctx.Operator = Operator.Clear; ctx.Fill(); } gr.SetSourceSurface(mask, 0, 0); gr.Paint(); using (Surface ol = new ImageSurface(Format.Argb32, cb.Width, cb.Height)) { using (Context ctx = new Context(ol)) { ctx.SetSourceColor(Color.Black); drawDesignOverlay(ctx, g, cb, hr, 0.4 / z, 6.5); } gr.SetSourceSurface(ol, 0, 0); gr.Paint(); } drawIcon(gr, icoMove, rIcoMove); //drawIcon (gr, icoStyle, rIcoStyle); } } if (HoverWidget != null) { hr = HoverWidget.ScreenCoordinates(HoverWidget.getSlot()); gr.SetSourceColor(Color.SkyBlue); //gr.SetDash (new double[]{ 5.0, 3.0 }, 0.0); gr.Rectangle(hr, 0.4 / z); } gr.Restore(); }
void UpdateBgImage() { m_bgImage = null; if (TextColumn < 0 || WeightColumn < 0) { return; } m_bgImage = new Cairo.ImageSurface(Format.Rgb24, Allocation.Width, this.Allocation.Height); using (var c = new Cairo.Context(m_bgImage)) { // Paint the default background (linear gradient) var g = new Cairo.LinearGradient(0, 0, 1, this.Allocation.Height); g.AddColorStop(0.2, CairoExtensions.GdkColorToCairoColor(m_Background)); g.AddColorStop(0.9, CairoExtensions.GdkColorToCairoColor(this.Style.Background(Gtk.StateType.Normal))); c.Rectangle(0, 0, this.Allocation.Width, this.Allocation.Height); c.Pattern = g; c.Paint(); g.Dispose(); Gtk.TreeIter iter; List <TreeMapItem> rootItems = new List <TreeMapItem> (); if (m_Model.GetIterFirst(out iter)) { do { var item = new TreeMapItem(m_Model, ref iter, true, m_TextColumn, m_WeightColumn); rootItems.Add(item); } while (m_Model.IterNext(ref iter)); double t = 0.0; rootItems.ForEach(delegate(TreeMapItem i) { t += Math.Abs(i.Weight); }); double x = 0, y = 0, w = this.Allocation.Width, h = this.Allocation.Height; double myx = 0, myy = 0, myw = 0, myh = 0; rootItems.ForEach(delegate(TreeMapItem i) { var ratio = Math.Abs(i.Weight) / t; myx = x; myy = y; myw = w * ratio; myh = h; x += myw; i.SetArea(myx, myy, myw, myh); i.Render(c, m_Background); }); // clear right away to lower refs if (this.m_rootItems != null) { this.m_rootItems.Clear(); } this.m_rootItems = rootItems; } } }