Esempio n. 1
0
 public override void Draw(Bitmap bitmap, int x, int y)
 {
     using (Cairo.Surface s = new BitmapSurface(bitmap)) {
         cr.SetSourceSurface(s, x + xOffset, y + yOffset);
         using (Cairo.SurfacePattern pattern = (Cairo.SurfacePattern)cr.GetSource()) {
             pattern.Filter = Cairo.Filter.Nearest;
         }
         cr.Paint();
     }
 }
Esempio n. 2
0
            public void Apply(Cairo.Context context)
            {
                if (!ReferenceEquals(Transform, null))
                {
                    context.Transform(Transform);
                }

                if (opacityImage == null)
                {
                    opacityImage = new Bitmap(Image.Size, PixelFormat.Format32bppRgba);
                    using (var g = new Graphics(opacityImage))
                    {
                        g.DrawImage(Image, 0, 0);
                    }
                    using (var bd = opacityImage.Lock())
                    {
                        for (int x = 0; x < opacityImage.Width; x++)
                        {
                            for (int y = 0; y < opacityImage.Height; y++)
                            {
                                var c = bd.GetPixel(x, y);
                                bd.SetPixel(x, y, new Color(c, c.A * Opacity));
                            }
                        }
                    }
                }
                var img = opacityImage ?? Image;

                Gdk.CairoHelper.SetSourcePixbuf(context, img.ToGdk(), 0, 0);

                var pattern        = context.GetSource();
                var surfacePattern = pattern as Cairo.SurfacePattern;

                if (surfacePattern != null)
                {
                    surfacePattern.Extend = Cairo.Extend.Repeat;
                }
                if (!ReferenceEquals(InverseTransform, null))
                {
                    context.Transform(InverseTransform);
                }

                pattern.Dispose();
            }