本文整理汇总了C#中Cairo.Context.SetSourceSurface方法的典型用法代码示例。如果您正苦于以下问题:C# Context.SetSourceSurface方法的具体用法?C# Context.SetSourceSurface怎么用?C# Context.SetSourceSurface使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cairo.Context
的用法示例。
在下文中一共展示了Context.SetSourceSurface方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
void Draw(Context cr, int width, int height)
{
double radius = 0.5 * Math.Min (width, height) - 10;
int xc = width / 2;
int yc = height / 2;
Surface overlay = cr.Target.CreateSimilar (Content.ColorAlpha, width, height);
Surface punch = cr.Target.CreateSimilar (Content.Alpha, width, height);
Surface circles = cr.Target.CreateSimilar (Content.ColorAlpha, width, height);
FillChecks (cr, 0, 0, width, height);
cr.Save ();
// Draw a black circle on the overlay
using (Context cr_overlay = new Context (overlay)) {
cr_overlay.Color = new Color (0.0, 0.0, 0.0);
OvalPath (cr_overlay, xc, yc, radius, radius);
cr_overlay.Fill ();
// Draw 3 circles to the punch surface, then cut
// that out of the main circle in the overlay
using (Context cr_tmp = new Context (punch))
Draw3Circles (cr_tmp, xc, yc, radius, 1.0);
cr_overlay.Operator = Operator.DestOut;
cr_overlay.SetSourceSurface (punch, 0, 0);
cr_overlay.Paint ();
// Now draw the 3 circles in a subgroup again
// at half intensity, and use OperatorAdd to join up
// without seams.
using (Context cr_circles = new Context (circles)) {
cr_circles.Operator = Operator.Over;
Draw3Circles (cr_circles, xc, yc, radius, 0.5);
}
cr_overlay.Operator = Operator.Add;
cr_overlay.SetSourceSurface (circles, 0, 0);
cr_overlay.Paint ();
}
cr.SetSourceSurface (overlay, 0, 0);
cr.Paint ();
overlay.Destroy ();
punch.Destroy ();
circles.Destroy ();
}
示例2: PlacedSurface
public PlacedSurface(ImageSurface source, Gdk.Rectangle roi)
{
where = roi.Location;
what = new ImageSurface (Format.Argb32, roi.Width, roi.Height);
using (Context g = new Context (what)) {
g.SetSourceSurface (source, -roi.X, -roi.Y);
g.Paint ();
}
}
示例3: copySurfacePart
private ImageSurface copySurfacePart(ImageSurface surf, Gdk.Rectangle dest_rect)
{
ImageSurface tmp_surface = new ImageSurface (Format.Argb32, dest_rect.Width, dest_rect.Height);
using (Context g = new Context (tmp_surface)) {
g.Operator = Operator.Source;
g.SetSourceSurface (surf, -dest_rect.Left, -dest_rect.Top);
g.Rectangle (new Rectangle (0, 0, dest_rect.Width, dest_rect.Height));
g.Fill ();
}
//Flush to make sure all drawing operations are finished
tmp_surface.Flush ();
return tmp_surface;
}
示例4: Render
public override void Render(Node node, Context context)
{
ImageNode image = node as ImageNode;
ImageSurface surfaceCache = image.Data as ImageSurface;
if (surfaceCache == null) {
surfaceCache = new ImageSurface (image.File);
}
int x = (int)((image.Width - surfaceCache.Width) * image.XAlign);
int y = (int)((image.Height - surfaceCache.Height) * image.YAlign);
context.SetSourceSurface (surfaceCache, x, y);
double opacity = image.Opacity;
if (opacity == 1)
context.Paint ();
else
context.PaintWithAlpha (image.Opacity);
}
示例5: Draw
void Draw(Context cr, int width, int height)
{
Surface overlay = cr.Target.CreateSimilar(Content.ColorAlpha, width, height);
Surface addSurface = cr.Target.CreateSimilar(Content.ColorAlpha, width, height);
// FillChecks (cr, 0, 0,width, height);//w, h);
// cr.Save ();
using (Context cr_overlay = new Context(overlay))
if (listPoint != null && listPoint.Count > 0) {
using (Context cr_addSurface = new Context(addSurface)) {
BarierPoint actualPoint;
BarierPoint nearstBP;
for (int i = 0; i < listPoint.Count; i++) {
actualPoint = listPoint[i];
if (i == listPoint.Count-1) {
nearstBP = listPoint[0];
} else
nearstBP = listPoint[i + 1];
Cairo.Color clrPoint;
if (actualPoint.Equals(movingPoint))
clrPoint =colorSelectPoint;
else
clrPoint = colorPoint;
cr_addSurface.Color = clrPoint;
OvalPath(cr_addSurface, actualPoint.X * scaling, actualPoint.Y * scaling, pointWidth, pointWidth);
cr_addSurface.Fill();
cr_addSurface.Color = colorLine;
LinePath(cr_addSurface, actualPoint.X * scaling, actualPoint.Y * scaling, nearstBP.X * scaling, nearstBP.Y * scaling);
cr_addSurface.Fill();
}
cr_overlay.Operator = Operator.Add;
cr_overlay.SetSourceSurface(addSurface, 0, 0);
cr_overlay.Paint();
}
cr.Scale(1 / scaling, 1 / scaling);
cr.SetSourceSurface(overlay, (int)(drawOffsetX), (int)(drawOffsetY));
cr.Paint();
}
addSurface.Destroy();
overlay.Destroy();
}
示例6: OnMouseDown
protected override void OnMouseDown(Gtk.DrawingArea canvas, Gtk.ButtonPressEventArgs args, Cairo.PointD point)
{
int x = (int)point.X;
int y = (int)point.Y;
if (args.Event.Button == 1)//Left
{
//Select an origin with Ctrl + Click
if((args.Event.State & Gdk.ModifierType.ControlMask) == Gdk.ModifierType.ControlMask)
{
from_point = new Point (x, y);
stamp = new Cairo.ImageSurface (PintaCore.Layers.CurrentLayer.Surface.Format, BrushWidth*2, BrushWidth*2);
from_point = ClampPoint(from_point);
using (Context g = new Context (stamp)) {
g.SetSourceSurface (PintaCore.Layers.CurrentLayer.Surface,
0 - (from_point.X - BrushWidth),
0 - (from_point.Y - BrushWidth));//dest - source
g.Rectangle(0, 0, BrushWidth * 2, BrushWidth * 2);
Gradient radpat = new RadialGradient(from_point.X, from_point.Y, BrushWidth, from_point.X, from_point.Y, BrushWidth);
radpat.AddColorStop(0, new Color(0, 0, 0, 1));
radpat.AddColorStop(1, new Color(0, 0, 0, 0));
g.Mask(radpat);
g.Fill ();
}
// Draw the copy
} else {
to_point = new Point (x, y);
if (PintaCore.Workspace.PointInCanvas (point) && !from_point.Equals (point_empty))
{
to_point = ClampPoint(to_point);
surface_modified = true;
undo_surface = PintaCore.Layers.CurrentLayer.Surface.Clone ();
ImageSurface surf = PintaCore.Layers.CurrentLayer.Surface;
using (Context g = new Context (surf)) {
g.SetSourceSurface (stamp, to_point.X - BrushWidth, to_point.Y - BrushWidth);
g.Paint ();
}
Gdk.Rectangle r = GetRectangleFromPoints (to_point, to_point);
PintaCore.Workspace.Invalidate ();
PintaCore.History.PushNewItem(new SimpleHistoryItem (Icon, Name,undo_surface, PintaCore.Layers.CurrentLayerIndex));
}
from_point = point_empty;
}
}
base.OnMouseDown (canvas, args, point);
}
示例7: ResizeCanvas
public void ResizeCanvas(int width, int height, Anchor anchor)
{
ImageSurface dest = new ImageSurface (Format.Argb32, width, height);
int delta_x = Surface.Width - width;
int delta_y = Surface.Height - height;
using (Context g = new Context (dest)) {
switch (anchor) {
case Anchor.NW:
g.SetSourceSurface (Surface, 0, 0);
break;
case Anchor.N:
g.SetSourceSurface (Surface, -delta_x / 2, 0);
break;
case Anchor.NE:
g.SetSourceSurface (Surface, -delta_x, 0);
break;
case Anchor.E:
g.SetSourceSurface (Surface, -delta_x, -delta_y / 2);
break;
case Anchor.SE:
g.SetSourceSurface (Surface, -delta_x, -delta_y);
break;
case Anchor.S:
g.SetSourceSurface (Surface, -delta_x / 2, -delta_y);
break;
case Anchor.SW:
g.SetSourceSurface (Surface, 0, -delta_y);
break;
case Anchor.W:
g.SetSourceSurface (Surface, 0, -delta_y / 2);
break;
case Anchor.Center:
g.SetSourceSurface (Surface, -delta_x / 2, -delta_y / 2);
break;
}
g.Paint ();
}
(Surface as IDisposable).Dispose ();
Surface = dest;
}
示例8: Crop
public void Crop(Rectangle rect)
{
ImageSurface dest = new ImageSurface (Format.Argb32, (int)rect.Width, (int)rect.Height);
using (Context g = new Context (dest)) {
g.SetSourceSurface (Surface, -(int)rect.X, -(int)rect.Y);
g.Paint ();
}
(Surface as IDisposable).Dispose ();
Surface = dest;
}
示例9: CombinePngs
public static void CombinePngs(List<ImagePlacement> placements, ParsedPath pngPath)
{
try
{
int w = 0;
int h = 0;
foreach (var placement in placements)
{
int wt = (int)placement.TargetRectangle.Width;
int ht = (int)placement.TargetRectangle.Height;
if (wt > w)
w = wt;
if (ht > h)
h = ht;
}
using (ImageSurface combinedImage = new ImageSurface(Format.Argb32, w, h))
{
using (Cairo.Context g = new Cairo.Context(combinedImage))
{
foreach (var placement in placements)
{
using (ImageSurface image = new ImageSurface(placement.ImageFile))
{
int x = (int)placement.TargetRectangle.X;
int y = (int)placement.TargetRectangle.Y;
g.SetSourceSurface(image, x, y);
g.Paint();
}
}
}
combinedImage.WriteToPng(pngPath);
}
}
catch (Exception e)
{
throw new ArgumentException("Unable to combine images into file '{0}'".CultureFormat(pngPath), e);
}
}
示例10: HandlerPintaCoreActionsEditCopyActivated
private void HandlerPintaCoreActionsEditCopyActivated(object sender, EventArgs e)
{
PintaCore.Layers.FinishSelection ();
ImageSurface src = PintaCore.Layers.GetClippedLayer (PintaCore.Layers.CurrentLayerIndex);
Cairo.Rectangle rect = PintaCore.Layers.SelectionPath.GetBounds ();
ImageSurface dest = new ImageSurface (Format.Argb32, (int)rect.Width, (int)rect.Height);
using (Context g = new Context (dest)) {
g.SetSourceSurface (src, -(int)rect.X, -(int)rect.Y);
g.Paint ();
}
Gtk.Clipboard cb = Gtk.Clipboard.Get (Gdk.Atom.Intern ("CLIPBOARD", false));
cb.Image = dest.ToPixbuf ();
(src as IDisposable).Dispose ();
(dest as IDisposable).Dispose ();
}
示例11: clip_image
public void clip_image(Context cr, int width, int height)
{
Normalize (cr, width, height);
cr.Arc (0.5, 0.5, 0.3, 0, 2*Math.PI);
cr.Clip ();
cr.NewPath (); // path not consumed by clip()
ImageSurface image = new ImageSurface ("data/romedalen.png");
int w = image.Width;
int h = image.Height;
cr.Scale (1.0/w, 1.0/h);
cr.SetSourceSurface (image, 0, 0);
cr.Paint ();
image.Destroy ();
}
示例12: RenderCell
private void RenderCell(Context g, int width, int height)
{
// Add some padding
width -= 2;
height -= 2;
double scale;
int draw_width = width;
int draw_height = height;
// The image is more constrained by height than width
if ((double)width / (double)surface.Width >= (double)height / (double)surface.Height) {
scale = (double)height / (double)(surface.Height);
draw_width = (int)(surface.Width * height / surface.Height);
} else {
scale = (double)width / (double)(surface.Width);
draw_height = (int)(surface.Height * width / surface.Width);
}
int offset_x = (int)((width - draw_width) / 2f);
int offset_y = (int)((height - draw_height) / 2f);
g.Save ();
g.Rectangle (offset_x, offset_y, draw_width, draw_height);
g.Clip ();
g.SetSource (transparent);
g.Paint ();
g.Scale (scale, scale);
g.SetSourceSurface (surface, (int)(offset_x / scale), (int)(offset_y / scale));
g.Paint ();
g.Restore ();
// TODO: scale this box correctly to match layer aspect ratio
g.Color = new Cairo.Color (0.5, 0.5, 0.5);
g.Rectangle (offset_x + 0.5, offset_y + 0.5, draw_width, draw_height);
g.LineWidth = 1;
g.Stroke ();
}
示例13: UpdateCache
protected override void UpdateCache(Context ctx)
{
Rectangle rb = Slot + Parent.ClientRectangle.Position;
using (ImageSurface cache = new ImageSurface (bmp, Format.Argb32, Slot.Width, Slot.Height, 4 * Slot.Width)) {
Context gr = new Context (cache);
if (Clipping.count > 0) {
Clipping.clearAndClip (gr);
onDraw (gr);
}
gr.Dispose ();
ctx.SetSourceSurface (cache, rb.X, rb.Y);
ctx.Paint ();
}
Clipping.Reset();
}
示例14: SetAsSource
public override void SetAsSource(Context ctx, Rectangle bounds = default(Rectangle))
{
float widthRatio = 1f;
float heightRatio = 1f;
if (Scaled){
widthRatio = (float)bounds.Width / Dimensions.Width;
heightRatio = (float)bounds.Height / Dimensions.Height;
}
if (KeepProportions) {
if (widthRatio < heightRatio)
heightRatio = widthRatio;
else
widthRatio = heightRatio;
}
using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
using (Cairo.Context gr = new Context (tmp)) {
gr.Translate (bounds.Left, bounds.Top);
gr.Scale (widthRatio, heightRatio);
gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.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 ();
}
}
ctx.SetSource (tmp);
}
}
示例15: pasteSurfacePart
private void pasteSurfacePart(Context g,ImageSurface tmp_surface, Gdk.Rectangle dest_rect)
{
g.Operator = Operator.Source;
g.SetSourceSurface (tmp_surface, dest_rect.Left, dest_rect.Top);
g.Rectangle (new Rectangle (dest_rect.Left, dest_rect.Top, dest_rect.Width, dest_rect.Height));
g.Fill ();
}