本文整理汇总了C#中Cairo.ImageSurface类的典型用法代码示例。如果您正苦于以下问题:C# ImageSurface类的具体用法?C# ImageSurface怎么用?C# ImageSurface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImageSurface类属于Cairo命名空间,在下文中一共展示了ImageSurface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public unsafe override void Render (ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois)
{
bacAdjustment.Data.Brightness = -Data.ColorRange;
bacAdjustment.Data.Contrast = -Data.ColorRange;
bacAdjustment.Render (src, dest, rois);
blurEffect.Data.Radius = Data.PencilTipSize;
blurEffect.Render (src, dest, rois);
invertEffect.Render (dest, dest, rois);
desaturateOp.Apply (dest, dest, rois);
ColorBgra* dst_dataptr = (ColorBgra*)dest.DataPtr;
int dst_width = dest.Width;
ColorBgra* src_dataptr = (ColorBgra*)src.DataPtr;
int src_width = src.Width;
foreach (Gdk.Rectangle roi in rois) {
for (int y = roi.Top; y <= roi.GetBottom (); ++y) {
ColorBgra* srcPtr = src.GetPointAddressUnchecked (src_dataptr, src_width, roi.X, y);
ColorBgra* dstPtr = dest.GetPointAddressUnchecked (dst_dataptr, dst_width, roi.X, y);
for (int x = roi.Left; x <= roi.GetRight (); ++x) {
ColorBgra srcGrey = desaturateOp.Apply (*srcPtr);
ColorBgra sketched = colorDodgeOp.Apply (srcGrey, *dstPtr);
*dstPtr = sketched;
++srcPtr;
++dstPtr;
}
}
}
}
示例2: ApplyRectangle
private unsafe void ApplyRectangle (ImageSurface surface, Gdk.Rectangle rect)
{
for (int y = rect.Left; y <= rect.GetBottom (); ++y) {
ColorBgra* ptr = surface.GetPointAddress (rect.Left, y);
Apply (ptr, rect.Width);
}
}
示例3: 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;
}
}
示例4: Paint
public override void Paint(Cairo.Context gr, Rectangle rect, string subPart = "")
{
float widthRatio = 1f;
float heightRatio = 1f;
if (Scaled){
widthRatio = (float)rect.Width / Dimensions.Width;
heightRatio = (float)rect.Height / Dimensions.Height;
}
if (KeepProportions) {
if (widthRatio < heightRatio)
heightRatio = widthRatio;
else
widthRatio = heightRatio;
}
gr.Save ();
gr.Translate (rect.Left,rect.Top);
gr.Scale (widthRatio, heightRatio);
gr.Translate ((rect.Width/widthRatio - Dimensions.Width)/2, (rect.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 ();
}
gr.Restore ();
}
示例5: RenderThumbnail
public static void RenderThumbnail (Cairo.Context cr, ImageSurface image, bool dispose,
double x, double y, double width, double height, bool drawBorder, double radius,
bool fill, Color fillColor)
{
RenderThumbnail (cr, image, dispose, x, y, width, height, drawBorder, radius,
fill, fillColor, CairoCorners.All);
}
示例6: TextHistoryItem
/// <summary>
/// A history item for when text is created, edited, and/or finalized.
/// </summary>
/// <param name="icon">The history item's icon.</param>
/// <param name="text">The history item's title.</param>
/// <param name="passedTextSurface">The stored TextLayer surface.</param>
/// <param name="passedUserSurface">The stored UserLayer surface.</param>
/// <param name="passedTextEngine">The text engine being used.</param>
/// <param name="passedUserLayer">The UserLayer being modified.</param>
public TextHistoryItem(string icon, string text, ImageSurface passedTextSurface,
ImageSurface passedUserSurface, TextEngine passedTextEngine,
UserLayer passedUserLayer) : base(icon, text)
{
userLayer = passedUserLayer;
text_surface_diff = SurfaceDiff.Create(passedTextSurface, userLayer.TextLayer.Layer.Surface, true);
if (text_surface_diff == null)
{
textSurface = passedTextSurface;
}
else
{
(passedTextSurface as IDisposable).Dispose();
}
user_surface_diff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true);
if (user_surface_diff == null)
{
userSurface = passedUserSurface;
}
else
{
(passedUserSurface as IDisposable).Dispose();
}
tEngine = passedTextEngine;
textBounds = new Gdk.Rectangle(userLayer.textBounds.X, userLayer.textBounds.Y, userLayer.textBounds.Width, userLayer.textBounds.Height);
}
示例7: 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);
}
示例8: ImageSize
public Size ImageSize(string file)
{
ImageSurface image = new ImageSurface (file);
Size result = new Size (image.Width, image.Height);
(image as IDisposable).Dispose ();
return result;
}
示例9: CreateTileBrush
public static SurfacePattern CreateTileBrush(TileBrush brush, Size targetSize)
{
var helper = new TileBrushImplHelper(brush, targetSize);
if (!helper.IsValid)
return null;
using (var intermediate = new ImageSurface(Format.ARGB32, (int)helper.IntermediateSize.Width, (int)helper.IntermediateSize.Height))
using (var ctx = new RenderTarget(intermediate).CreateDrawingContext())
{
helper.DrawIntermediate(ctx);
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(-helper.DestinationRect.X, -helper.DestinationRect.Y);
result.Matrix = matrix;
}
return result;
}
}
示例10: 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.
}
}
}
示例11: 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;
}
示例12: Render
unsafe public override void Render (ImageSurface src, ImageSurface dst, Gdk.Rectangle[] rois)
{
const double jr = 0.3125;
const double ji = 0.03;
int w = dst.Width;
int h = dst.Height;
double invH = 1.0 / h;
double invZoom = 1.0 / Data.Zoom;
double invQuality = 1.0 / Data.Quality;
double aspect = (double)h / (double)w;
int count = Data.Quality * Data.Quality + 1;
double invCount = 1.0 / (double)count;
double angleTheta = (Data.Angle * Math.PI * 2) / 360.0;
ColorBgra* dst_dataptr = (ColorBgra*)dst.DataPtr;
int dst_width = dst.Width;
foreach (Gdk.Rectangle rect in rois) {
for (int y = rect.Top; y <= rect.GetBottom (); y++) {
ColorBgra* dstPtr = dst.GetPointAddressUnchecked (dst_dataptr, dst_width, rect.Left, y);
for (int x = rect.Left; x <= rect.GetRight (); x++) {
int r = 0;
int g = 0;
int b = 0;
int a = 0;
for (double i = 0; i < count; i++) {
double u = (2.0 * x - w + (i * invCount)) * invH;
double v = (2.0 * y - h + ((i * invQuality) % 1)) * invH;
double radius = Math.Sqrt ((u * u) + (v * v));
double radiusP = radius;
double theta = Math.Atan2 (v, u);
double thetaP = theta + angleTheta;
double uP = radiusP * Math.Cos (thetaP);
double vP = radiusP * Math.Sin (thetaP);
double jX = (uP - vP * aspect) * invZoom;
double jY = (vP + uP * aspect) * invZoom;
double j = Julia (jX, jY, jr, ji);
double c = Data.Factor * j;
b += Utility.ClampToByte (c - 768);
g += Utility.ClampToByte (c - 512);
r += Utility.ClampToByte (c - 256);
a += Utility.ClampToByte (c - 0);
}
*dstPtr = ColorBgra.FromBgra (Utility.ClampToByte (b / count), Utility.ClampToByte (g / count), Utility.ClampToByte (r / count), Utility.ClampToByte (a / count));
++dstPtr;
}
}
}
}
示例13: Image_Loaded
private void Image_Loaded(object sender, RoutedEventArgs e)
{
Image image = (Image)sender;
using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)image.Width, (int)image.Height))
{
using (Context context = new Context(surface))
{
PointD p = new PointD(10.0, 10.0);
PointD p2 = new PointD(100.0, 10.0);
PointD p3 = new PointD(100.0, 100.0);
PointD p4 = new PointD(10.0, 100.0);
context.MoveTo(p);
context.LineTo(p2);
context.LineTo(p3);
context.LineTo(p4);
context.LineTo(p);
context.ClosePath();
context.Fill();
context.MoveTo(140.0, 110.0);
context.SetFontSize(32.0);
context.SetSourceColor(new Color(0.0, 0.0, 0.8, 1.0));
context.ShowText("Hello Cairo!");
surface.Flush();
RgbaBitmapSource source = new RgbaBitmapSource(surface.Data, surface.Width);
image.Source = source;
}
}
}
示例14: ShapesHistoryItem
/// <summary>
/// A history item for when shapes are finalized.
/// </summary>
/// <param name="passedEE">The EditEngine being used.</param>
/// <param name="icon">The history item's icon.</param>
/// <param name="text">The history item's title.</param>
/// <param name="passedUserSurface">The stored UserLayer surface.</param>
/// <param name="passedUserLayer">The UserLayer being modified.</param>
/// <param name="passedSelectedPointIndex">The selected point's index.</param>
/// <param name="passedSelectedShapeIndex">The selected point's shape index.</param>
/// <param name="passedRedrawEverything">Whether every shape should be redrawn when undoing (e.g. finalization).</param>
public ShapesHistoryItem(BaseEditEngine passedEE, string icon, string text, ImageSurface passedUserSurface, UserLayer passedUserLayer,
int passedSelectedPointIndex, int passedSelectedShapeIndex, bool passedRedrawEverything) : base(icon, text)
{
ee = passedEE;
userLayer = passedUserLayer;
userSurfaceDiff = SurfaceDiff.Create(passedUserSurface, userLayer.Surface, true);
if (userSurfaceDiff == null)
{
userSurface = passedUserSurface;
}
else
{
(passedUserSurface as IDisposable).Dispose();
}
sEngines = BaseEditEngine.SEngines.PartialClone();
selectedPointIndex = passedSelectedPointIndex;
selectedShapeIndex = passedSelectedShapeIndex;
redrawEverything = passedRedrawEverything;
}
示例15: 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);
}