本文整理汇总了C#中Cairo.Context类的典型用法代码示例。如果您正苦于以下问题:C# Context类的具体用法?C# Context怎么用?C# Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Context类属于Cairo命名空间,在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Form1_Shown
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);
}
开发者ID:zwcloud,项目名称:ZWCloud.DwriteCairo,代码行数:31,代码来源:Form1.cs
示例2: GtkGraphDrawer
public GtkGraphDrawer(Context g, Context gh, ImageSurface srfc)
{
this.g = g;
this.gh = gh;
this.srfc = srfc;
gh.Antialias = Antialias.Subpixel;
}
开发者ID:ivynetca,项目名称:lapsestudio,代码行数:7,代码来源:GtkGraphDrawer.cs
示例3: 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
示例4: Main
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.
}
}
}
开发者ID:zwcloud,项目名称:CairoSharp,代码行数:33,代码来源:Program.cs
示例5: DrawGraduations
protected override void DrawGraduations(Context gr, PointD pStart, PointD pEnd)
{
Rectangle r = ClientRectangle;
Foreground.SetAsSource (gr);
gr.LineWidth = 2;
gr.MoveTo(pStart);
gr.LineTo(pEnd);
gr.Stroke();
gr.LineWidth = 1;
double sst = unity * SmallIncrement;
double bst = unity * LargeIncrement;
PointD vBar = new PointD(0, sst);
for (double x = Minimum; x <= Maximum - Minimum; x += SmallIncrement)
{
double lineLength = r.Height / 3;
if (x % LargeIncrement != 0)
lineLength /= 3;
PointD p = new PointD(pStart.X + x * unity, pStart.Y);
gr.MoveTo(p);
gr.LineTo(new PointD(p.X, p.Y + lineLength));
}
gr.Stroke();
}
开发者ID:jpbruyere,项目名称:Crow,代码行数:27,代码来源:GraduatedSlider.cs
示例6: Create
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;
}
}
开发者ID:Yetangitu,项目名称:f-spot,代码行数:34,代码来源:PixbufImageSurface.cs
示例7: CreateBlur
private ImageInfo CreateBlur (ImageInfo source)
{
double scale = Math.Max (256 / (double) source.Bounds.Width,
256 / (double) source.Bounds.Height);
Gdk.Rectangle small = new Gdk.Rectangle (0, 0,
(int) Math.Ceiling (source.Bounds.Width * scale),
(int) Math.Ceiling (source.Bounds.Height * scale));
MemorySurface image = new MemorySurface (Format.Argb32,
small.Width,
small.Height);
Context ctx = new Context (image);
//Pattern solid = new SolidPattern (0, 0, 0, 0);
//ctx.Source = solid;
//ctx.Paint ();
//solid.Destroy ();
ctx.Matrix = source.Fit (small);
ctx.Operator = Operator.Source;
Pattern p = new SurfacePattern (source.Surface);
ctx.Source = p;
//Log.Debug (small);
ctx.Paint ();
p.Destroy ();
((IDisposable)ctx).Dispose ();
Gdk.Pixbuf normal = MemorySurface.CreatePixbuf (image);
Gdk.Pixbuf blur = PixbufUtils.Blur (normal, 3);
ImageInfo overlay = new ImageInfo (blur);
blur.Dispose ();
normal.Dispose ();
image.Destroy ();
return overlay;
}
开发者ID:guadalinex-archive,项目名称:guadalinex-v6,代码行数:34,代码来源:SoftFocus.cs
示例8: OnTransformIp
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);
}
开发者ID:jwzl,项目名称:ossbuild,代码行数:29,代码来源:TransformSample.cs
示例9: OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
using (System.Drawing.Graphics graphics = e.Graphics)
{
using (Win32Surface surface = new Win32Surface(graphics.GetHdc()))
{
using (Context context = new Context(surface))
{
context.LineWidth = 2.0;
context.SetSourceColor(this.bugColor);
context.MoveTo(7.0, 64.0);
context.CurveTo(1.0, 47.0, 2.0, 46.0, 9.0, 51.0);
context.MoveTo(25.0, 80.0);
context.CurveTo(10.0, 73.0, 11.0, 70.0, 14.0, 63.0);
context.MoveTo(10.0, 41.0);
context.CurveTo(2.0, 36.0, 1.0, 33.0, 1.0, 26.0);
context.LineWidth = 1.0;
context.MoveTo(1.0, 26.0);
context.CurveTo(5.0, 23.0, 7.0, 18.0, 12.0, 17.0);
context.LineTo(12.0, 14.0);
context.Stroke();
context.MoveTo(30.0, 74.0);
context.CurveTo(14.0, 64.0, 10.0, 48.0, 11.0, 46.0);
context.LineTo(10.0, 45.0);
context.LineTo(10.0, 40.0);
context.CurveTo(13.0, 37.0, 15.0, 35.0, 19.0, 34.0);
context.Stroke();
}
}
}
}
开发者ID:zwcloud,项目名称:CairoSharp,代码行数:32,代码来源:Form1.cs
示例10: Run
public override void Run()
{
ICollection<double> chapters = this.Theory.Chapters;
StripCanvasSize scs = this.Manager.GenerateStripCanvasSize (chapters.Count);
double dw = scs.CanvasSize.Width;
double dh = scs.CanvasSize.Height;
using (PdfSurface surface = new PdfSurface (this.Manager.OutputFile, scs.TotalWidth, scs.TotalHeight)) {
using (Context ctx = new Context (surface)) {
int index = 0x00;
IPoint3 p;
foreach (double chapter in chapters) {
p = scs.GetCanvasOffset (index);
ctx.Save ();
ctx.Translate (p.X, p.Y);
ctx.Rectangle (0.0d, 0.0d, dw, dh);
ctx.Stroke ();
this.Theory.Time = chapter;
CairoEngine engine = new CairoEngine (this.Theory);
engine.Context = ctx;
engine.Process ();
ctx.Restore ();
index++;
}
}
}
}
开发者ID:KULeuven-KRR,项目名称:IdpGie,代码行数:26,代码来源:OutputPdfStripDevice.cs
示例11: DrawArrow
public override void DrawArrow(Context cr, Gdk.Rectangle alloc, SortType type)
{
cr.LineWidth = 1;
cr.Translate (0.5, 0.5);
double x1 = alloc.X;
double x3 = alloc.X + alloc.Width / 2.0;
double x2 = x3 + (x3 - x1);
double y1 = alloc.Y;
double y2 = alloc.Bottom;
if (type == SortType.Ascending) {
cr.MoveTo (x1, y1);
cr.LineTo (x2, y1);
cr.LineTo (x3, y2);
cr.LineTo (x1, y1);
} else {
cr.MoveTo (x3, y1);
cr.LineTo (x2, y2);
cr.LineTo (x1, y2);
cr.LineTo (x3, y1);
}
cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal));
cr.FillPreserve ();
cr.SetSourceColor (Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal));
cr.Stroke ();
cr.Translate (-0.5, -0.5);
}
开发者ID:Kalnor,项目名称:monodevelop,代码行数:28,代码来源:GtkTheme.cs
示例12: Apply
public override void Apply (CanvasItem item, Context cr)
{
int steps = ShadowSize;
double opacity_step = ShadowOpacity / ShadowSize;
Color color = new Color (0, 0, 0);
double width = Math.Round (item.Allocation.Width);
double height = Math.Round (item.Allocation.Height);
if (Fill != null) {
cr.Rectangle (shadow_size, shadow_size, width - ShadowSize * 2, height - ShadowSize * 2);
Fill.Apply (cr);
cr.Fill ();
}
cr.LineWidth = 1.0;
for (int i = 0; i < steps; i++) {
CairoExtensions.RoundedRectangle (cr,
i + 0.5,
i + 0.5,
(width - 2 * i) - 1,
(height - 2 * i) - 1,
steps - i);
color.A = opacity_step * (i + 1);
cr.Color = color;
cr.Stroke ();
}
}
开发者ID:fatman2021,项目名称:gnome-apps,代码行数:30,代码来源:ShadowMarginStyle.cs
示例13: SketchPad
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;
}
开发者ID:KommuSoft,项目名称:CplKul2012,代码行数:7,代码来源:SketchPad.cs
示例14: UpdateRectangle
protected void UpdateRectangle (PointD point)
{
if (!is_drawing)
return;
Document doc = PintaCore.Workspace.ActiveDocument;
Rectangle r = PointsToRectangle (shape_origin, point);
Rectangle dirty;
doc.ToolLayer.Clear ();
doc.ToolLayer.Hidden = false;
using (Context g = new Context (doc.ToolLayer.Surface)) {
g.Antialias = Antialias.Subpixel;
dirty = g.FillStrokedRectangle (r, new Color (0, 0.4, 0.8, 0.1), new Color (0, 0, 0.9), 1);
dirty = dirty.Clamp ();
doc.Workspace.Invalidate (last_dirty.ToGdkRectangle ());
doc.Workspace.Invalidate (dirty.ToGdkRectangle ());
last_dirty = dirty;
}
}
开发者ID:msiyer,项目名称:Pinta,代码行数:25,代码来源:ZoomTool.cs
示例15: OnMouseMove
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;
}
开发者ID:msiyer,项目名称:Pinta,代码行数:28,代码来源:PlainBrush.cs
示例16: Draw
public virtual void Draw(Context cr, Gdk.Rectangle clip)
{
cr.Rectangle(clip.X, clip.Y, clip.Width, clip.Height);
cr.Color = BackgroundColor;
cr.Fill();
cr.Stroke();
}
开发者ID:JianwenSun,项目名称:mono-soc-2007,代码行数:7,代码来源:Paper.cs
示例17: OnFillRegionComputed
protected unsafe 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;
ColorBgra* surf_data_ptr = (ColorBgra*)surface.DataPtr;
int surf_width = surface.Width;
for (int x = 0; x < stencil.Width; x++)
for (int y = 0; y < stencil.Height; y++)
if (stencil.GetUnchecked (x, y))
surface.SetPixel (surf_data_ptr, surf_width, 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:xxgreg,项目名称:Pinta,代码行数:30,代码来源:PaintBucketTool.cs
示例18: clip
public void clip(Context ctx)
{
foreach (Rectangle r in list)
ctx.Rectangle(r);
ctx.Clip();
}
开发者ID:jpbruyere,项目名称:Crow,代码行数:7,代码来源:Rectangles.cs
示例19: Draw
public override void Draw(Context context)
{
SetupLayout(context);
RectangleD displayBox = DisplayBox;
displayBox.OffsetDot5();
double side = 10.0;
context.LineWidth = LineWidth;
context.Save ();
//Box
context.MoveTo (displayBox.X, displayBox.Y);
context.LineTo (displayBox.X, displayBox.Y + displayBox.Height);
context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + displayBox.Height);
context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + side);
context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y);
context.LineTo (displayBox.X, displayBox.Y);
context.Save ();
//Triangle
context.MoveTo (displayBox.X + displayBox.Width - side, displayBox.Y);
context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y + side);
context.LineTo (displayBox.X + displayBox.Width, displayBox.Y + side);
context.LineTo (displayBox.X + displayBox.Width - side, displayBox.Y);
context.Restore ();
context.Color = FillColor;
context.FillPreserve ();
context.Color = LineColor;
context.Stroke ();
DrawText (context);
}
开发者ID:mono,项目名称:monohotdraw,代码行数:32,代码来源:NoteFigure.cs
示例20: CreateImageBrush
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;
}
}
开发者ID:shahid-pk,项目名称:Perspex,代码行数:60,代码来源:TileBrushes.cs
注:本文中的Cairo.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论