本文整理汇总了C#中Cairo.ImageSurface类的典型用法代码示例。如果您正苦于以下问题:C# Cairo.ImageSurface类的具体用法?C# Cairo.ImageSurface怎么用?C# Cairo.ImageSurface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Cairo.ImageSurface类属于命名空间,在下文中一共展示了Cairo.ImageSurface类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CairoSurfaceWrapper
public unsafe CairoSurfaceWrapper (Cairo.ImageSurface surface)
{
this.surface = surface;
this.data_ptr = (ColorBgra*)surface.DataPtr;
height = surface.Height;
width = surface.Width;
}
开发者ID:PintaProject,项目名称:Pinta.ImageManipulation,代码行数:7,代码来源:CairoSurfaceWrapper.cs
示例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);
}
}
开发者ID:msiyer,项目名称:Pinta,代码行数:11,代码来源:GdkExtensions.cs
示例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);
}
}
开发者ID:rdterner,项目名称:Perspex,代码行数:12,代码来源:StreamGeometryContextImpl.cs
示例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;
}
开发者ID:garuma,项目名称:xwt,代码行数:13,代码来源:ImagePatternBackendHandler.cs
示例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;
}
开发者ID:chkn,项目名称:xwt,代码行数:14,代码来源:ContextBackendHandler.cs
示例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);
}
}
}
开发者ID:msiyer,项目名称:Pinta,代码行数:14,代码来源:PointPickerGraphic.cs
示例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 ();
}
开发者ID:bvssvni,项目名称:csharp-utils,代码行数:15,代码来源:TestDrawing.cs
示例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;
}
}
开发者ID:Octavio,项目名称:moro.PresentationFramework,代码行数:15,代码来源:FormattedText.cs
示例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 ();
}
开发者ID:msiyer,项目名称:Pinta,代码行数:45,代码来源:CanvasRenderer.cs
示例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 ();
}
开发者ID:bvssvni,项目名称:csharp-utils,代码行数:21,代码来源:TestDrawing.cs
示例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;
}
开发者ID:jbeaurain,项目名称:xwt,代码行数:22,代码来源:ImagePatternBackendHandler.cs
示例12: GtkTextLayoutBackendHandler
static GtkTextLayoutBackendHandler()
{
using (Cairo.Surface sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1)) {
SharedContext = new Cairo.Context (sf);
}
}
开发者ID:samclarke,项目名称:xwt,代码行数:6,代码来源:TextLayoutBackendHandler.cs
示例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);
}
开发者ID:ericksson,项目名称:Pinta,代码行数:35,代码来源:LayersListWidget.cs
示例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 ();
}
开发者ID:jobernolte,项目名称:Pinta,代码行数:37,代码来源:AsyncEffectRenderer.cs
示例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;
}
开发者ID:msiyer,项目名称:Pinta,代码行数:11,代码来源:GdkExtensions.cs
示例16: OnExposeEvent
protected override bool OnExposeEvent(EventExpose e)
{
base.OnExposeEvent (e);
if (!PintaCore.Workspace.HasOpenDocuments)
return true;
double scale = PintaCore.Workspace.Scale;
int x = (int)PintaCore.Workspace.Offset.X;
int y = (int)PintaCore.Workspace.Offset.Y;
// Translate our expose area for the whole drawingarea to just our canvas
Rectangle canvas_bounds = new Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height);
canvas_bounds.Intersect (e.Area);
if (canvas_bounds.IsEmpty)
return true;
canvas_bounds.X -= x;
canvas_bounds.Y -= y;
// Resize our offscreen surface to a surface the size of our drawing area
if (canvas == null || canvas.Width != canvas_bounds.Width || canvas.Height != canvas_bounds.Height) {
if (canvas != null)
(canvas as IDisposable).Dispose ();
canvas = new Cairo.ImageSurface (Cairo.Format.Argb32, canvas_bounds.Width, canvas_bounds.Height);
}
cr.Initialize (PintaCore.Workspace.ImageSize, PintaCore.Workspace.CanvasSize);
using (Cairo.Context g = CairoHelper.Create (GdkWindow)) {
// Draw our canvas drop shadow
g.DrawRectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width + 1, PintaCore.Workspace.CanvasSize.Height + 1), new Cairo.Color (.5, .5, .5), 1);
g.DrawRectangle (new Cairo.Rectangle (x - 1, y - 1, PintaCore.Workspace.CanvasSize.Width + 3, PintaCore.Workspace.CanvasSize.Height + 3), new Cairo.Color (.8, .8, .8), 1);
g.DrawRectangle (new Cairo.Rectangle (x - 2, y - 2, PintaCore.Workspace.CanvasSize.Width + 5, PintaCore.Workspace.CanvasSize.Height + 5), new Cairo.Color (.9, .9, .9), 1);
// Set up our clip rectangle
g.Rectangle (new Cairo.Rectangle (x, y, PintaCore.Workspace.CanvasSize.Width, PintaCore.Workspace.CanvasSize.Height));
g.Clip ();
g.Translate (x, y);
// Render all the layers to a surface
var layers = PintaCore.Layers.GetLayersToPaint ();
if (layers.Count == 0) {
canvas.Clear ();
}
cr.Render (layers, canvas, canvas_bounds.Location);
// Paint the surface to our canvas
g.SetSourceSurface (canvas, canvas_bounds.X + (int)(0 * scale), canvas_bounds.Y + (int)(0 * scale));
g.Paint ();
// Selection outline
if (PintaCore.Layers.ShowSelection) {
g.Save ();
g.Translate (0.5, 0.5);
g.Scale (scale, scale);
g.AppendPath (PintaCore.Layers.SelectionPath);
if (PintaCore.Tools.CurrentTool.Name.Contains ("Select") && !PintaCore.Tools.CurrentTool.Name.Contains ("Selected")) {
g.Color = new Cairo.Color (0.7, 0.8, 0.9, 0.2);
g.FillRule = Cairo.FillRule.EvenOdd;
g.FillPreserve ();
}
g.LineWidth = 1 / scale;
// Draw a white line first so it shows up on dark backgrounds
g.Color = new Cairo.Color (1, 1, 1);
g.StrokePreserve ();
// Draw a black dashed line over the white line
g.SetDash (new double[] { 2 / scale, 4 / scale }, 0);
g.Color = new Cairo.Color (0, 0, 0);
g.Stroke ();
g.Restore ();
}
}
return true;
}
开发者ID:rini18,项目名称:Pinta,代码行数:86,代码来源:PintaCanvas.cs
示例17: BuildImage
public Gdk.Pixbuf BuildImage(FontService fontService)
{
Cairo.ImageSurface image = new Cairo.ImageSurface (Cairo.Format.ARGB32, WIDTH, HEIGHT);
Cairo.Context ctx = new Cairo.Context (image);
Pango.Layout layout = Pango.CairoHelper.CreateLayout (ctx);
fontService.AssignLayout (layout);
// fill background
ctx.Save ();
ctx.Color = new Cairo.Color (0.0, 0.0, 0.0, 1.0);
ctx.Paint ();
ctx.Restore ();
int charCode = 0;
int maxHeight = 0;
Cairo.Point pos = new Cairo.Point (PADDING, PADDING);
while ((!fontService.OnlyEnglish && charCode < 224) ||
(fontService.OnlyEnglish && charCode < (224 - 66))) {
layout.SetText (alphabet[charCode].ToString());
Pango.Rectangle te = GetTextExtents (layout, pos);
// next line
if (pos.X + te.Width + fontService.Spacing + PADDING > image.Width) {
pos.X = PADDING;
pos.Y = te.Y + maxHeight + PADDING;
}
te = DrawText (ctx, layout, pos);
boxes[charCode] = te;
pos.X = te.X + te.Width + fontService.Spacing + PADDING;
maxHeight = Math.Max (maxHeight, te.Height);
charCode++;
}
int cropHeight = NextP2 (boxes[charCode - 1].Y + boxes[charCode - 1].Height - 1);
Gdk.Pixbuf pixbuf = new Gdk.Pixbuf (
image.Data, true, 8,
image.Width,
cropHeight,
image.Stride);
// manual dispose
(image as IDisposable).Dispose ();
(layout as IDisposable).Dispose ();
(ctx.Target as IDisposable).Dispose ();
(ctx as IDisposable).Dispose ();
return pixbuf;
}
开发者ID:MagistrTot,项目名称:DGLE,代码行数:53,代码来源:DftUtil.cs
示例18: RenderFrame
Gdk.Pixbuf RenderFrame(ApplicationContext actx, double scaleFactor, double width, double height)
{
using (var sf = new Cairo.ImageSurface (Cairo.Format.ARGB32, (int)(width * scaleFactor), (int)(height * scaleFactor)))
using (var ctx = new Cairo.Context (sf)) {
ImageDescription idesc = new ImageDescription () {
Alpha = 1,
Size = new Size (width * scaleFactor, height * scaleFactor)
};
Draw (actx, ctx, 1, 0, 0, idesc);
var f = new ImageFrame (ImageBuilderBackend.CreatePixbuf (sf), (int)width, (int)height);
AddFrame (f);
return f.Pixbuf;
}
}
开发者ID:neiz,项目名称:xwt,代码行数:14,代码来源:ImageHandler.cs
示例19: Playback
Cairo.Context Playback ()
{
using (var surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 10, 10))
{
var context = new Cairo.Context(surface);
Apply(context);
return context;
}
}
开发者ID:JohnACarruthers,项目名称:Eto,代码行数:9,代码来源:GraphicsPathHandler.cs
示例20: DrawText
private void DrawText(Cairo.ImageSurface dst, string textFont, string text, Point pt, Size measuredSize, bool antiAliasing, Cairo.Color color)
{
Rectangle dstRect = new Rectangle (pt, measuredSize);
//Rectangle dstRectClipped = Rectangle.Intersect(dstRect, ScratchSurface.Bounds);
/*
if (dstRectClipped.Width == 0 || dstRectClipped.Height == 0)
{
return;
}
*/
using (Cairo.ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.Argb32, 8, 8)) {
using (Cairo.Context context = new Cairo.Context (surface)) {
context.FillRectangle (new Cairo.Rectangle (0, 0, surface.Width, surface.Height), color);
}
DrawText (dst, textFont, text, pt, measuredSize, antiAliasing, surface);
}
}
开发者ID:xxgreg,项目名称:Pinta,代码行数:18,代码来源:TextTool.cs
注:本文中的Cairo.ImageSurface类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论