本文整理汇总了C#中Cairo.ImageSurface类的典型用法代码示例。如果您正苦于以下问题:C# Cairo.ImageSurface类的具体用法?C# Cairo.ImageSurface怎么用?C# Cairo.ImageSurface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cairo.ImageSurface类属于命名空间,在下文中一共展示了Cairo.ImageSurface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CairoSurfaceWrapper
public unsafe CairoSurfaceWrapper (Cairo.ImageSurface surface)
{
this.surface = surface;
this.data_ptr = (ColorBgra*)surface.DataPtr;
height = surface.Height;
width = surface.Width;
}
示例2: WithAlpha
public static Gdk.Pixbuf WithAlpha (this Gdk.Pixbuf image, double opacity)
{
using (var surf = new Cairo.ImageSurface (Cairo.Format.Argb32, image.Width, image.Height)) {
using (var g = new Cairo.Context (surf)) {
CairoHelper.SetSourcePixbuf (g, image, 0, 0);
g.PaintWithAlpha (opacity);
}
return new Gdk.Pixbuf (surf.Data, true, 8, surf.Width, surf.Height, surf.Stride);
}
}
示例3: StreamGeometryContextImpl
public StreamGeometryContextImpl(Cairo.Path path = null)
{
_surf = new Cairo.ImageSurface (Cairo.Format.Argb32, 0, 0);
_context = new Cairo.Context (_surf);
this.Path = path;
if (this.Path != null)
{
_context.AppendPath(this.Path);
}
}
示例4: Create
public override object Create(object img)
{
Gdk.Pixbuf pb = (Gdk.Pixbuf)img;
var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, pb.Width, pb.Height);
var ic = new Cairo.Context (imgs);
Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
ic.Paint ();
imgs.Flush ();
((IDisposable)ic).Dispose ();
var p = new Cairo.SurfacePattern (imgs);
p.Extend = Cairo.Extend.Repeat;
return p;
}
示例5: CreateContext
public object CreateContext(Widget w)
{
GtkContext ctx = new GtkContext ();
var b = (IGtkWidgetBackend)WidgetRegistry.GetBackend (w);
if (!b.Widget.IsRealized) {
Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
Cairo.Context c = new Cairo.Context (sf);
ctx.Context = c;
ctx.TempSurface = sf;
} else {
ctx.Context = Gdk.CairoHelper.Create (b.Widget.GdkWindow);
}
return ctx;
}
示例6: UpdateThumbnail
private void UpdateThumbnail ()
{
double scalex = (double)Allocation.Width / (double)PintaCore.Workspace.ImageSize.Width;
double scaley = (double)Allocation.Height / (double)PintaCore.Workspace.ImageSize.Height;
thumbnail = new Cairo.ImageSurface (Cairo.Format.Argb32, Allocation.Width, Allocation.Height);
using (Cairo.Context g = new Cairo.Context (thumbnail)) {
g.Scale (scalex, scaley);
foreach (Layer layer in PintaCore.Layers.GetLayersToPaint ()) {
layer.Draw(g);
}
}
}
示例7: TestDrawLine
public void TestDrawLine()
{
var bytes = new byte[1024 * 4];
var format = Cairo.Format.ARGB32;
var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
var shape = new LineShape (0.0, 0.0, 32.0, 32.0);
var look = new Look (SolidBrush.Red, SolidPen.Black);
var op = new ShapeTree (look, shape);
using (var context = new Cairo.Context (image)) {
op.Draw (context);
}
image.WriteToPng ("testimages/line.png");
image.Dispose ();
}
示例8: Measure
private void Measure ()
{
var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1);
using (Cairo.Context cr = new Cairo.Context(surface)) {
cr.SelectFontFace (FontFamily, Cairo.FontSlant.Normal, Cairo.FontWeight.Normal);
cr.SetFontSize (FontSize);
var textExtents = cr.TextExtents (Text);
Width = textExtents.Width;
Height = Math.Abs (textExtents.YBearing);
Extent = textExtents.Height;
}
}
示例9: Render
public void Render (List<Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset)
{
dst.Flush ();
// Our rectangle of interest
var r = new Gdk.Rectangle (offset, dst.GetBounds ().Size).ToCairoRectangle ();
using (var g = new Cairo.Context (dst)) {
// Create the transparent checkerboard background
g.Translate (-offset.X, -offset.Y);
g.FillRectangle (r, tranparent_pattern, new Cairo.PointD (offset.X, offset.Y));
for (var i = 0; i < layers.Count; i++) {
var layer = layers[i];
// If we're in LivePreview, substitute current layer with the preview layer
if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
layer = CreateLivePreviewLayer (layer);
// If the layer is offset, handle it here
if (!layer.Transform.IsIdentity ())
layer = CreateOffsetLayer (layer);
// No need to resize the surface if we're at 100% zoom
if (scale_factor.Ratio == 1)
layer.Draw (g, layer.Surface, layer.Opacity, false);
else {
using (var scaled = new Cairo.ImageSurface (Cairo.Format.Argb32, dst.Width, dst.Height)) {
g.Save ();
// Have to undo the translate set above
g.Translate (offset.X, offset.Y);
CopyScaled (layer.Surface, scaled, r.ToGdkRectangle ());
layer.Draw (g, scaled, layer.Opacity, false);
g.Restore ();
}
}
}
}
// If we are at least 200% and grid is requested, draw it
if (enable_pixel_grid && PintaCore.Actions.View.PixelGrid.Active && scale_factor.Ratio <= 0.5d)
RenderPixelGrid (dst, offset);
dst.MarkDirty ();
}
示例10: TestDrawRectangle
public void TestDrawRectangle()
{
var bytes = new byte[1024 * 4];
var format = Cairo.Format.ARGB32;
var image = new Cairo.ImageSurface (bytes, format, 32, 32, 32 * 4);
var shape = new RectangleShape ();
shape.Rectangle = new Rectangle () {
X = 10.0,
Y = 10.0,
Width = 12.0,
Height = 12.0
};
var look = new Look (SolidBrush.Red, SolidPen.Black);
var op = new ShapeTree (look, shape);
using (var context = new Cairo.Context (image)) {
op.Draw (context);
}
image.WriteToPng ("testimages/rectangle.png");
image.Dispose ();
}
示例11: GetPattern
public Cairo.Pattern GetPattern(ApplicationContext actx, double scaleFactor)
{
if (pattern == null || currentScaleFactor != scaleFactor) {
if (pattern != null)
pattern.Dispose ();
Gdk.Pixbuf pb = ((GtkImage)Image.Backend).GetBestFrame (actx, scaleFactor, Image.Size.Width, Image.Size.Height, false);
var imgs = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(Image.Size.Width * scaleFactor), (int)(Image.Size.Height * scaleFactor));
var ic = new Cairo.Context (imgs);
ic.Scale ((double)imgs.Width / (double)pb.Width, (double)imgs.Height / (double)pb.Height);
Gdk.CairoHelper.SetSourcePixbuf (ic, pb, 0, 0);
ic.Paint ();
imgs.Flush ();
((IDisposable)ic).Dispose ();
pattern = new Cairo.SurfacePattern (imgs);
pattern.Extend = Cairo.Extend.Repeat;
var cm = new Cairo.Matrix ();
cm.Scale (scaleFactor, scaleFactor);
pattern.Matrix = cm;
currentScaleFactor = scaleFactor;
}
return pattern;
}
示例12: GtkTextLayoutBackendHandler
static GtkTextLayoutBackendHandler()
{
using (Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1)) {
SharedContext = new Cairo.Context (sf);
}
}
示例13: Reset
public void Reset()
{
store.Clear ();
if (active_layer_surface != null) {
active_layer_surface.Dispose ();
active_layer_surface = null;
}
if (!PintaCore.Workspace.HasOpenDocuments)
return;
var doc = PintaCore.Workspace.ActiveDocument;
foreach (var layer in (doc.UserLayers as IEnumerable<Layer>).Reverse ()) {
var surf = layer.Surface;
// Draw the selection layer on top of the active layer.
if (layer == doc.CurrentUserLayer && doc.ShowSelectionLayer) {
active_layer_surface = new Cairo.ImageSurface (Cairo.Format.Argb32, thumbnail_width,
thumbnail_height);
canvas_renderer.Initialize (doc.ImageSize,
new Gdk.Size (thumbnail_width, thumbnail_height));
var layers = new List<Layer> { layer, doc.SelectionLayer };
canvas_renderer.Render (layers, active_layer_surface, Gdk.Point.Zero);
surf = active_layer_surface;
}
store.AppendValues (surf, layer.Name, !layer.Hidden, layer);
}
SelectLayerInTreeView (PintaCore.Layers.Count - PintaCore.Layers.CurrentLayerIndex - 1);
}
示例14: Start
internal void Start (BaseEffect effect,
Cairo.ImageSurface source,
Cairo.ImageSurface dest,
Gdk.Rectangle renderBounds)
{
Debug.WriteLine ("AsyncEffectRenderer.Start ()");
if (effect == null)
throw new ArgumentNullException ("effect");
if (source == null)
throw new ArgumentNullException ("source");
if (dest == null)
throw new ArgumentNullException ("dest");
if (renderBounds.IsEmpty)
throw new ArgumentException ("renderBounds.IsEmpty");
// It is important the effect's properties don't change during rendering.
// So a copy is made for the render.
this.effect = effect.Clone();
this.source_surface = source;
this.dest_surface = dest;
this.render_bounds = renderBounds;
// If a render is already in progress, then cancel it,
// and start a new render.
if (IsRendering) {
cancel_render_flag = true;
restart_render_flag = true;
return;
}
StartRender ();
}
示例15: ToSurface
public static Cairo.Surface ToSurface (this Pixbuf pixbuf)
{
var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, pixbuf.Width, pixbuf.Height);
using (var g = new Cairo.Context (surface)) {
Gdk.CairoHelper.SetSourcePixbuf (g, pixbuf, 0, 0);
g.Paint ();
}
return surface;
}