本文整理汇总了C#中Cairo.Surface类的典型用法代码示例。如果您正苦于以下问题:C# Surface类的具体用法?C# Surface怎么用?C# Surface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Surface类属于Cairo命名空间,在下文中一共展示了Surface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImageInfo
public ImageInfo(ImageInfo info, Gdk.Rectangle allocation)
{
#if false
Surface = new ImageSurface (Format.RGB24,
allocation.Width,
allocation.Height);
Context ctx = new Context (Surface);
#else
Console.WriteLine ("source status = {0}", info.Surface.Status);
Surface = info.Surface.CreateSimilar (Content.Color,
allocation.Width,
allocation.Height);
System.Console.WriteLine ("status = {1} pointer = {0}", Surface.Handle.ToString (), Surface.Status);
Context ctx = new Context (Surface);
#endif
Bounds = allocation;
ctx.Matrix = info.Fill (allocation);
Pattern p = new SurfacePattern (info.Surface);
ctx.Source = p;
ctx.Paint ();
((IDisposable)ctx).Dispose ();
p.Destroy ();
}
示例2: SurfaceToPngBytes
public static byte[] SurfaceToPngBytes(Surface surface)
{
using (var ms = new MemoryStream())
{
SurfaceToPngStream(surface, ms);
return ms.ToArray();
}
}
示例3: SurfaceToPngStream
public static void SurfaceToPngStream(Surface surface, BinaryWriter writer)
{
var obj = new CairoStreamWriter(writer);
var fn = new cairo_write_func_t(obj.do_write);
var status = cairo_surface_write_to_png_stream(surface.Handle, fn, IntPtr.Zero);
if (status != Status.Success)
throw new InvalidOperationException("Status: " + status);
}
示例4: CellRendererSurface
public CellRendererSurface(int width, int height)
{
// TODO: Respect cell padding (Xpad and Ypad).
SetFixedSize (width, height);
transparent = new Cairo.ImageSurface (Cairo.Format.ARGB32, width, height);
Cairo.Color gray = new Cairo.Color (.75, .75, .75);
// Create checkerboard background
int grid_width = 4;
using (Cairo.Context g = new Cairo.Context (transparent)) {
g.Color = new Cairo.Color (1, 1, 1);
g.Paint ();
for (int y = 0; y < height; y += grid_width)
for (int x = 0; x < width; x += grid_width)
if ((x / grid_width % 2) + (y / grid_width % 2) == 1)
g.FillRectangle (new Cairo.Rectangle (x, y, grid_width, grid_width), gray);
}
}
示例5: ClearDrawing
public void ClearDrawing()
{
drawings.Destroy();
drawings = new ImageSurface(Format.ARGB32,sourceWidth,sourceHeight);
QueueDraw();
}
示例6: CreatePixbuf
private static Gdk.Pixbuf CreatePixbuf(Surface s)
{
IntPtr result = f_pixbuf_from_cairo_surface (s.Handle);
return (Gdk.Pixbuf) GLib.Object.GetObject (result, true);
}
示例7: Graphics
public Graphics(Surface surface)
: base(surface)
{
}
示例8: SetTarget
public void SetTarget(Surface target)
{
if (handle != IntPtr.Zero)
NativeMethods.cairo_destroy (handle);
handle = NativeMethods.cairo_create (target.Handle);
}
示例9: SetSource
public void SetSource(Surface source)
{
NativeMethods.cairo_set_source_surface (handle, source.Handle, 0, 0);
}
示例10: MaskSurface
public void MaskSurface(Surface surface, double surface_x, double surface_y)
{
NativeMethods.cairo_mask_surface (handle, surface.Handle, surface_x, surface_y);
}
示例11: Invert
/// <summary>
/// Inverts the selection.
/// </summary>
/// <param name="surface">
/// Surface for the selection path.
/// </param>
/// <param name='imageSize'>
/// The size of the document.
/// </param>
public void Invert(Surface surface, Gdk.Size imageSize)
{
List<List<IntPoint>> resultingPolygons = new List<List<IntPoint>> ();
var documentPolygon = CreateRectanglePolygon (new Rectangle (0, 0, imageSize.Width, imageSize.Height));
// Create a rectangle that is the size of the entire image,
// and subtract all of the polygons in the current selection from it.
SelectionClipper.AddPolygon (documentPolygon, PolyType.ptSubject);
SelectionClipper.AddPolygons (SelectionPolygons, PolyType.ptClip);
SelectionClipper.Execute (ClipType.ctDifference, resultingPolygons);
SelectionClipper.Clear ();
SelectionPolygons = resultingPolygons;
using (Context g = new Context (surface)) {
SelectionPath = g.CreatePolygonPath (ConvertToPolygonSet (resultingPolygons));
}
}
示例12: CreateEllipseSelection
/// <summary>
/// Create an elliptical Selection from a bounding Rectangle.
/// </summary>
/// <param name="selectionSurface">The selection surface to use for calculating the elliptical Path.</param>
/// <param name="r">The bounding Rectangle surrounding the ellipse.</param>
public void CreateEllipseSelection(Surface selectionSurface, Rectangle r)
{
using (Context g = new Context(selectionSurface))
{
SelectionPath = g.CreateEllipsePath(r);
}
//These values were calculated in the static CreateEllipsePath method
//in Pinta.Core.CairoExtensions, so they were used here as well.
double rx = r.Width / 2; //1/2 of the bounding Rectangle Width.
double ry = r.Height / 2; //1/2 of the bounding Rectangle Height.
double cx = r.X + rx; //The middle of the bounding Rectangle, horizontally speaking.
double cy = r.Y + ry; //The middle of the bounding Rectangle, vertically speaking.
double c1 = 0.552285; //A constant factor used to give the least approximation error.
//Clear the Selection Polygons collection to start from a clean slate.
SelectionPolygons.Clear();
//Calculate an appropriate interval at which to increment t based on
//the bounding Rectangle's Width and Height properties. The increment
//for t determines how many intermediate Points to calculate for the
//ellipse. For each curve, t will go from tInterval to 1. The lower
//the value of tInterval, the higher number of intermediate Points
//that will be calculated and stored into the Polygon collection.
double tInterval = 1d / (r.Width + r.Height);
//Create a new Polygon to store the upcoming ellipse.
List<IntPoint> newPolygon = new List<IntPoint>();
//These values were also calculated in the CreateEllipsePath method. This is where
//the ellipse's 4 curves (and all of the Points on each curve) are determined.
//Note: each curve is consecutive to the previous one, but they *do not* overlap,
//other than the first/last Point (which is how it is supposed to work).
//The starting Point.
newPolygon.Add(new IntPoint((long)(cx + rx), (long)cy));
//Curve 1.
newPolygon.AddRange(CalculateCurvePoints(tInterval,
cx + rx, cy,
cx + rx, cy - c1 * ry,
cx + c1 * rx, cy - ry,
cx, cy - ry));
//Curve 2.
newPolygon.AddRange(CalculateCurvePoints(tInterval,
cx, cy - ry,
cx - c1 * rx, cy - ry,
cx - rx, cy - c1 * ry,
cx - rx, cy));
//Curve 3.
newPolygon.AddRange(CalculateCurvePoints(tInterval,
cx - rx, cy,
cx - rx, cy + c1 * ry,
cx - c1 * rx, cy + ry,
cx, cy + ry));
//Curve 4.
newPolygon.AddRange(CalculateCurvePoints(tInterval,
cx, cy + ry,
cx + c1 * rx, cy + ry,
cx + rx, cy + c1 * ry,
cx + rx, cy));
//Add the newly calculated elliptical Polygon.
SelectionPolygons.Add(newPolygon);
}
示例13: SetPixbuf
private void SetPixbuf(Pixbuf pixbuf)
{
Surface = CairoUtils.CreateSurface (pixbuf);
Bounds.Width = pixbuf.Width;
Bounds.Height = pixbuf.Height;
}
示例14: Pattern
public Pattern(Surface surface)
{
pattern = NativeMethods.cairo_pattern_create_for_surface (surface.Handle);
}
示例15: ImageInfo
public ImageInfo(ImageInfo info, Gdk.Rectangle allocation)
{
Surface = info.Surface.CreateSimilar (Content.Color,
allocation.Width,
allocation.Height);
var ctx = new Context (Surface);
Bounds = allocation;
ctx.Matrix = info.Fill (allocation);
Pattern p = new SurfacePattern (info.Surface);
ctx.SetSource (p);
ctx.Paint ();
ctx.Dispose ();
p.Dispose ();
}