当前位置: 首页>>代码示例>>C#>>正文


C# Context.SetSource方法代码示例

本文整理汇总了C#中Cairo.Context.SetSource方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SetSource方法的具体用法?C# Context.SetSource怎么用?C# Context.SetSource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cairo.Context的用法示例。


在下文中一共展示了Context.SetSource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Render

        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 ();
        }
开发者ID:imagineblueeyes,项目名称:KaleidoscopeGenerator,代码行数:27,代码来源:CairoRenderer.cs

示例2: OnFillRegionComputed

        protected override void OnFillRegionComputed(Point[][] polygonSet)
        {
            SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
            hist.TakeSnapshotOfLayer (PintaCore.Layers.CurrentLayer);

            PintaCore.Layers.ToolLayer.Clear ();
            ImageSurface surface = PintaCore.Layers.ToolLayer.Surface;

            for (int x = 0; x < stencil.Width; x++)
                for (int y = 0; y < stencil.Height; y++)
                    if (stencil.GetUnchecked (x, y))
                        surface.SetPixel (x, y, fill_color);

            using (Context g = new Context (PintaCore.Layers.CurrentLayer.Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = Antialias.Subpixel;

                g.SetSource (surface);
                g.Paint ();
            }

            PintaCore.History.PushNewItem (hist);
            PintaCore.Workspace.Invalidate ();
        }
开发者ID:deckarep,项目名称:Pinta,代码行数:27,代码来源:PaintBucketTool.cs

示例3: create_big_starred_image

        public static Gtk.Image create_big_starred_image(string pic_path)
        {
            using (Cairo.ImageSurface img_surface = new ImageSurface(pic_path)) {
                using (Cairo.ImageSurface surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, img_surface.Width + 2, img_surface.Height + 2)) {
                    using (Cairo.Context context = new Context(surface)) {
                        Gdk.Pixbuf tmp_pixbuf = new Gdk.Pixbuf(pic_path);
                        if (!tmp_pixbuf.HasAlpha) { // img_surface.Format not available...
                            context.Rectangle(0, 0, img_surface.Width+2, img_surface.Height+2);
                            context.Fill();
                            context.Stroke();
                        }

                        context.SetSource(img_surface, 1, 1);
                        context.Paint();

                        // evil hack because the interface to cairo is pretty bad

                        Assembly asm = Assembly.GetCallingAssembly();

                        Stream s = asm.GetManifestResourceStream("big_star.png");

                        FileStream fs = new System.IO.FileStream(tmp_image_path, FileMode.Create);

                        for (int i = 0; i < s.Length; ++i)
                            fs.WriteByte((byte)s.ReadByte());

                        fs.Close();

                        using (Cairo.ImageSurface star_surface = new ImageSurface(tmp_image_path)) {
                            System.IO.File.Delete(tmp_image_path);

                            context.SetSource(star_surface, img_surface.Width-star_surface.Width, img_surface.Height-star_surface.Height);
                            context.Paint();

                            surface.WriteToPng(tmp_image_path);
                            Gtk.Image img = new Gtk.Image(tmp_image_path);
                            System.IO.File.Delete(tmp_image_path);
                            return img;
                        }
                    }
                }
            }
        }
开发者ID:GNOME,项目名称:nemo,代码行数:43,代码来源:Cairo.cs

示例4: Clone

        public static ImageSurface Clone(this ImageSurface surf)
        {
            ImageSurface newsurf = new ImageSurface (surf.Format, surf.Width, surf.Height);

            using (Context g = new Context (newsurf)) {
                g.SetSource (surf);
                g.Paint ();
            }

            return newsurf;
        }
开发者ID:pzsysa,项目名称:gtk-sharp-forms,代码行数:11,代码来源:CairoExtensions.cs

示例5: DrawBackground

		protected override void DrawBackground (Context context, Gdk.Rectangle region)
		{
			LayoutRoundedRectangle (context, region);
			context.Clip ();

			context.SetSourceColor (CairoExtensions.ParseColor ("D3E6FF"));
			context.Paint ();

			context.Save ();
			context.Translate (region.X + region.Width / 2.0, region.Y + region.Height);

			using (var rg = new RadialGradient (0, 0, 0, 0, 0, region.Height * 1.2)) {
				var color = CairoExtensions.ParseColor ("E5F0FF");
				rg.AddColorStop (0, color);
				color.A = 0;
				rg.AddColorStop (1, color);

				context.Scale (region.Width / (double)region.Height, 1.0);
				context.SetSource (rg);
				context.Paint ();
			}

			context.Restore ();

			LayoutRoundedRectangle (context, region, -3, -3, 2);
			context.SetSourceRGBA (1, 1, 1, 0.4);
			context.LineWidth = 1;
			context.StrokePreserve ();

			context.Clip ();

			int boxSize = 11;
			int x = region.Left + (region.Width % boxSize) / 2;
			for (; x < region.Right; x += boxSize) {
				context.MoveTo (x + 0.5, region.Top);
				context.LineTo (x + 0.5, region.Bottom);
			}

			int y = region.Top + (region.Height % boxSize) / 2;
			y += boxSize / 2;
			for (; y < region.Bottom; y += boxSize) {
				context.MoveTo (region.Left, y + 0.5);
				context.LineTo (region.Right, y + 0.5);
			}

			context.SetSourceRGBA (1, 1, 1, 0.2);
			context.Stroke ();

			context.ResetClip ();
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:50,代码来源:StatusAreaBuildTheme.cs

示例6: OnFillRegionComputed

		protected unsafe override void OnFillRegionComputed (IBitVector2D stencil)
		{
			Document doc = PintaCore.Workspace.ActiveDocument;
			ImageSurface surf = doc.ToolLayer.Surface;

			using (var g = new Context (surf)) {
				g.Operator = Operator.Source;
				g.SetSource (doc.CurrentUserLayer.Surface);
				g.Paint ();
			}

			SimpleHistoryItem hist = new SimpleHistoryItem (Icon, Name);
			hist.TakeSnapshotOfLayer (doc.CurrentUserLayer);

			ColorBgra color = fill_color.ToColorBgra ().ToPremultipliedAlpha ();
			ColorBgra* dstPtr = (ColorBgra*)surf.DataPtr;
			int width = surf.Width;

			surf.Flush ();

			// Color in any pixel that the stencil says we need to fill
			Parallel.For (0, stencil.Height, y =>
			{
				int stencil_width = stencil.Width;
				for (int x = 0; x < stencil_width; ++x) {
					if (stencil.GetUnchecked (x, y)) {
						surf.SetColorBgraUnchecked (dstPtr, width, color, x, y);
					}
				}
			});

			surf.MarkDirty ();

			// Transfer the temp layer to the real one,
			// respecting any selection area
			using (var g = doc.CreateClippedContext ()) {
				g.Operator = Operator.Source;
				g.SetSource (surf);
				g.Paint ();
			}

			doc.ToolLayer.Clear ();

			doc.History.PushNewItem (hist); 
			doc.Workspace.Invalidate ();
		}
开发者ID:msiyer,项目名称:Pinta,代码行数:46,代码来源:PaintBucketTool.cs

示例7: Render

        public override void Render(Context cr)
        {
            if (!CanResize) {
                return;
            }

            var selected_color = CairoExtensions.GdkRGBAToCairoColor (Window.StyleContext.GetColor (StateFlags.Selected));
            var grad = new LinearGradient (0, 0, 0, Allocation.Height);

            selected_color.A = 0.4;
            grad.AddColorStop (0, selected_color);
            selected_color.A = 1.0;
            grad.AddColorStop (1, selected_color);

            cr.SetSource (grad);
            cr.LineWidth = 1.0;
            cr.Rectangle (0.5, 0.5, Allocation.Width - 1, Allocation.Height - 1);
            cr.Stroke ();

            selected_color.A = 0.5;
            cr.SetSourceColor (selected_color);

            double handle_size = 8;
            double ty = 0.5 + Allocation.Height - handle_size - 3;
            double tx = 0.5 + (Window.Direction == TextDirection.Ltr
                ? Allocation.Width - handle_size - 3
                : 3);

            cr.Translate (tx, ty);

            for (double i = 0; i < 3; i++) {
                if (Window.Direction == TextDirection.Ltr) {
                    cr.MoveTo (i * 3, handle_size);
                    cr.LineTo (handle_size, i * 3);
                } else {
                    cr.MoveTo (0, i * 3);
                    cr.LineTo (handle_size - i * 3, handle_size);
                }
            }

            cr.Stroke ();

            cr.Translate (-tx, -ty);
        }
开发者ID:stsundermann,项目名称:cubano,代码行数:44,代码来源:CubanoWindowDecorator.cs

示例8: Export

        /// <summary>
        /// Exports the specified <see cref="PlotModel" /> to a png file.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="fileName">Name of the output file.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background color.</param>
        public static void Export(IPlotModel model, string fileName, int width, int height, Pattern background = null)
        {
            using (var bm = new ImageSurface(Format.ARGB32, width, height))
            {
                using (var g = new Context(bm))
                {
                    if (background != null)
                    {
                        g.Save();
                        g.SetSource(background);
                        g.Rectangle(0, 0, width, height);
                        g.Fill();
                        g.Restore();
                    }

                    var rc = new GraphicsRenderContext { RendersToScreen = false };
                    rc.SetGraphicsTarget(g);
                    model.Update(true);
                    model.Render(rc, width, height);
                    bm.WriteToPng(fileName);
                }
            }
        }
开发者ID:Celderon,项目名称:oxyplot,代码行数:31,代码来源:PngExporter.cs

示例9: FillChecks

	void FillChecks (Context cr, int x, int y, int width, int height)
	{
		int CHECK_SIZE = 32;
		
		cr.Save ();
		Surface check;
		using (var target = cr.GetTarget ()) {
			check = target.CreateSimilar (Content.Color, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
		}
		
		// draw the check
		using (Context cr2 = new Context (check)) {
			cr2.Operator = Operator.Source;
			cr2.SetSourceRGB (0.4, 0.4, 0.4);
			cr2.Rectangle (0, 0, 2 * CHECK_SIZE, 2 * CHECK_SIZE);
			cr2.Fill ();

			cr2.SetSourceRGB (0.7, 0.7, 0.7);
			cr2.Rectangle (x, y, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();

			cr2.Rectangle (x + CHECK_SIZE, y + CHECK_SIZE, CHECK_SIZE, CHECK_SIZE);
			cr2.Fill ();
		}

		// Fill the whole surface with the check
		SurfacePattern check_pattern = new SurfacePattern (check);
		check_pattern.Extend = Extend.Repeat;
		cr.SetSource (check_pattern);
		cr.Rectangle (0, 0, width, height);
		cr.Fill ();

		check_pattern.Dispose ();
		check.Dispose ();
		cr.Restore ();
	}
开发者ID:akrisiun,项目名称:gtk-sharp,代码行数:36,代码来源:CairoSample.cs

示例10: DrawTab

		void DrawTab (Context ctx, DockNotebookTab tab, Gdk.Rectangle allocation, Gdk.Rectangle tabBounds, bool highlight, bool active, bool dragging, Pango.Layout la)
		{
			// This logic is stupid to have here, should be in the caller!
			if (dragging) {
				tabBounds.X = (int)(tabBounds.X + (dragX - tabBounds.X) * dragXProgress);
				tabBounds.X = Clamp (tabBounds.X, tabStartX, tabEndX - tabBounds.Width);
			}
			double rightPadding = (active ? TabActivePadding.Right : TabPadding.Right) - (LeanWidth / 2);
			rightPadding = (rightPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0)));
			double leftPadding = (active ? TabActivePadding.Left : TabPadding.Left) - (LeanWidth / 2);
			leftPadding = (leftPadding * Math.Min (1.0, Math.Max (0.5, (tabBounds.Width - 30) / 70.0)));
			double bottomPadding = active ? TabActivePadding.Bottom : TabPadding.Bottom;

			DrawTabBackground (this, ctx, allocation, tabBounds.Width, tabBounds.X, active);

			ctx.LineWidth = 1;
			ctx.NewPath ();

			// Render Close Button (do this first so we can tell how much text to render)

			var closeButtonAlloation = new Cairo.Rectangle (tabBounds.Right - rightPadding - (tabCloseImage.Width / 2) - CloseButtonMarginRight,
			                                 tabBounds.Height - bottomPadding - tabCloseImage.Height - CloseButtonMarginBottom,
			                                 tabCloseImage.Width, tabCloseImage.Height);
			
			tab.CloseButtonActiveArea = closeButtonAlloation.Inflate (2, 2);

			bool closeButtonHovered = tracker.Hovered && tab.CloseButtonActiveArea.Contains (tracker.MousePosition);
			bool tabHovered = tracker.Hovered && tab.Allocation.Contains (tracker.MousePosition);
			bool drawCloseButton = active || tabHovered;

			if (!closeButtonHovered && tab.DirtyStrength > 0.5) {
				ctx.DrawImage (this, tabDirtyImage, closeButtonAlloation.X, closeButtonAlloation.Y);
				drawCloseButton = false;
			}

			if (drawCloseButton)
				ctx.DrawImage (this, tabCloseImage.WithAlpha ((closeButtonHovered ? 1.0 : 0.5) * tab.Opacity), closeButtonAlloation.X, closeButtonAlloation.Y);
			
			// Render Text
			double tw = tabBounds.Width - (leftPadding + rightPadding);
			if (drawCloseButton || tab.DirtyStrength > 0.5)
				tw -= closeButtonAlloation.Width / 2;

			double tx = tabBounds.X + leftPadding;
			var baseline = la.GetLine (0).Layout.GetPixelBaseline ();
			double ty = tabBounds.Height - bottomPadding - baseline;

			ctx.MoveTo (tx, ty);
			if (!MonoDevelop.Core.Platform.IsMac && !MonoDevelop.Core.Platform.IsWindows) {
				// This is a work around for a linux specific problem.
				// A bug in the proprietary ATI driver caused TAB text not to draw.
				// If that bug get's fixed remove this HACK asap.
				la.Ellipsize = Pango.EllipsizeMode.End;
				la.Width = (int)(tw * Pango.Scale.PangoScale);
				ctx.SetSourceColor ((tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor ());
				Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout);
			} else {
				// ellipses are for space wasting ..., we cant afford that
				using (var lg = new LinearGradient (tx + tw - 10, 0, tx + tw, 0)) {
					var color = (tab.Notify ? Styles.TabBarNotifyTextColor : (active ? Styles.TabBarActiveTextColor : Styles.TabBarInactiveTextColor)).ToCairoColor ();
					color = color.MultiplyAlpha (tab.Opacity);
					lg.AddColorStop (0, color);
					color.A = 0;
					lg.AddColorStop (1, color);
					ctx.SetSource (lg);
					Pango.CairoHelper.ShowLayout (ctx, la.GetLine (0).Layout);
				}
			}
            la.Dispose ();
		}
开发者ID:FreeBSD-DotNet,项目名称:monodevelop,代码行数:70,代码来源:TabStrip.cs

示例11: HueSaturation

        public unsafe void HueSaturation(int hueDelta, int satDelta, int lightness)
        {
            ImageSurface dest = Surface.Clone ();
            ColorBgra* dstPtr = (ColorBgra*)dest.DataPtr;

            int len = Surface.Data.Length / 4;

            // map the range [0,100] -> [0,100] and the range [101,200] -> [103,400]
            if (satDelta > 100)
                satDelta = ((satDelta - 100) * 3) + 100;

            UnaryPixelOp op;

            if (hueDelta == 0 && satDelta == 100 && lightness == 0)
                op = new UnaryPixelOps.Identity ();
            else
                op = new UnaryPixelOps.HueSaturationLightness (hueDelta, satDelta, lightness);

            op.Apply (dstPtr, len);

            using (Context g = new Context (Surface)) {
                g.AppendPath (PintaCore.Layers.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.SetSource (dest);
                g.Paint ();
            }

            (dest as IDisposable).Dispose ();
        }
开发者ID:deckarep,项目名称:Pinta,代码行数:31,代码来源:Layer.cs

示例12: Crop

        public void Crop(Gdk.Rectangle rect, Path path)
        {
            ImageSurface dest = new ImageSurface (Format.Argb32, rect.Width, rect.Height);

            using (Context g = new Context (dest)) {
                // Move the selected content to the upper left
                g.Translate (-rect.X, -rect.Y);
                g.Antialias = Antialias.None;

                // Respect the selected path
                g.AppendPath (path);
                g.FillRule = Cairo.FillRule.EvenOdd;
                g.Clip ();

                g.SetSource (Surface);
                g.Paint ();
            }

            (Surface as IDisposable).Dispose ();
            Surface = dest;
        }
开发者ID:jobernolte,项目名称:Pinta,代码行数:21,代码来源:Layer.cs

示例13: Rotate

        /// <summary>
        /// Rotates layer by the specified angle (in degrees).
        /// </summary>
        /// <param name='angle'>
        /// Angle (in degrees).
        /// </param>
        public void Rotate(double angle)
        {
            int w = PintaCore.Workspace.ImageSize.Width;
            int h = PintaCore.Workspace.ImageSize.Height;

            double radians = (angle / 180d) * Math.PI;
            double cos = Math.Cos (radians);
            double sin = Math.Sin (radians);

            var newSize = RotateDimensions (PintaCore.Workspace.ImageSize, angle);

            Layer dest = PintaCore.Layers.CreateLayer (string.Empty, newSize.Width, newSize.Height);

            using (Cairo.Context g = new Cairo.Context (dest.Surface)) {
                g.Matrix = new Matrix (cos, sin, -sin, cos, newSize.Width / 2.0, newSize.Height / 2.0);
                g.Translate (-w / 2.0, -h / 2.0);
                g.SetSource (Surface);

                g.Paint ();
            }

            Surface old = Surface;
            Surface = dest.Surface;
            (old as IDisposable).Dispose ();
        }
开发者ID:jobernolte,项目名称:Pinta,代码行数:31,代码来源:Layer.cs

示例14: PlaceSurface

		void PlaceSurface (Context cr, DockySurface surface, Gdk.Rectangle allocation)
		{
			int iconSize = allocation.Height - IconBuffer * 2;
			
			int x = allocation.X + Padding + ((iconSize - surface.Width) / 2);
			int y = allocation.Y + IconBuffer + ((iconSize - surface.Height) / 2);
			
			cr.SetSource (surface.Internal, x, y);
		}
开发者ID:Aurora-and-Equinox,项目名称:docky,代码行数:9,代码来源:MenuItemWidget.cs

示例15: OnMouseMove

        protected unsafe override void OnMouseMove(object o, Gtk.MotionNotifyEventArgs args, Cairo.PointD point)
        {
            Document doc = PintaCore.Workspace.ActiveDocument;

            ColorBgra old_color;
            ColorBgra new_color;

            if (mouse_button == 1) {
                old_color = PintaCore.Palette.PrimaryColor.ToColorBgra ();
                new_color = PintaCore.Palette.SecondaryColor.ToColorBgra ();
            } else if (mouse_button == 3) {
                old_color = PintaCore.Palette.SecondaryColor.ToColorBgra ();
                new_color = PintaCore.Palette.PrimaryColor.ToColorBgra ();
            } else {
                last_point = point_empty;
                return;
            }

            int x = (int)point.X;
            int y = (int)point.Y;

            if (last_point.Equals (point_empty))
                last_point = new Point (x, y);

            if (doc.Workspace.PointInCanvas (point))
                surface_modified = true;

            ImageSurface surf = doc.CurrentLayer.Surface;
            ImageSurface tmp_layer = doc.ToolLayer.Surface;

            Gdk.Rectangle roi = GetRectangleFromPoints (last_point, new Point (x, y));

            roi = PintaCore.Workspace.ClampToImageSize (roi);
            myTolerance = (int)(Tolerance * 256);

            tmp_layer.Flush ();

            ColorBgra* tmp_data_ptr = (ColorBgra*)tmp_layer.DataPtr;
            int tmp_width = tmp_layer.Width;
            ColorBgra* surf_data_ptr = (ColorBgra*)surf.DataPtr;
            int surf_width = surf.Width;

            // The stencil lets us know if we've already checked this
            // pixel, providing a nice perf boost
            // Maybe this should be changed to a BitVector2DSurfaceAdapter?
            for (int i = roi.X; i <= roi.GetRight (); i++)
                for (int j = roi.Y; j <= roi.GetBottom (); j++) {
                    if (stencil[i, j])
                        continue;

                    if (IsColorInTolerance (new_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j)))
                        *tmp_layer.GetPointAddressUnchecked (tmp_data_ptr, tmp_width, i, j) = AdjustColorDifference (new_color, old_color, surf.GetColorBgra (surf_data_ptr, surf_width, i, j));

                    stencil[i, j] = true;
                }

            tmp_layer.MarkDirty ();

            using (Context g = new Context (surf)) {
                g.AppendPath (doc.Selection.SelectionPath);
                g.FillRule = FillRule.EvenOdd;
                g.Clip ();

                g.Antialias = UseAntialiasing ? Antialias.Subpixel : Antialias.None;

                g.MoveTo (last_point.X, last_point.Y);
                g.LineTo (x, y);

                g.LineWidth = BrushWidth;
                g.LineJoin = LineJoin.Round;
                g.LineCap = LineCap.Round;

                g.SetSource (tmp_layer);

                g.Stroke ();
            }

            doc.Workspace.Invalidate (roi);

            last_point = new Point (x, y);
        }
开发者ID:cameronwhite,项目名称:Pinta,代码行数:81,代码来源:RecolorTool.cs


注:本文中的Cairo.Context.SetSource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。