Exemple #1
0
            public XImageCursor(IntPtr display, IBitmapImpl bitmap, PixelPoint hotSpot)
            {
                var size = Marshal.SizeOf <XcursorImage>() +
                           (bitmap.PixelSize.Width * bitmap.PixelSize.Height * 4);
                var runtimePlatform = AvaloniaLocator.Current.GetService <IRuntimePlatform>() ??
                                      throw new InvalidOperationException("Unable to locate IRuntimePlatform");
                var platformRenderInterface = AvaloniaLocator.Current.GetService <IPlatformRenderInterface>() ??
                                              throw new InvalidOperationException("Unable to locate IPlatformRenderInterface");

                _pixelSize = bitmap.PixelSize;
                _blob      = runtimePlatform.AllocBlob(size);

                var image = (XcursorImage *)_blob.Address;

                image->version = 1;
                image->size    = Marshal.SizeOf <XcursorImage>();
                image->width   = bitmap.PixelSize.Width;
                image->height  = bitmap.PixelSize.Height;
                image->xhot    = hotSpot.X;
                image->yhot    = hotSpot.Y;
                image->pixels  = (IntPtr)(image + 1);

                using (var renderTarget = platformRenderInterface.CreateRenderTarget(new[] { this }))
                    using (var ctx = renderTarget.CreateDrawingContext(null))
                    {
                        var r = new Rect(_pixelSize.ToSize(1));
                        ctx.DrawBitmap(RefCountable.CreateUnownedNotClonable(bitmap), 1, r, r);
                    }

                Handle = XLib.XcursorImageLoadCursor(display, _blob.Address);
            }
        public override void Save(Stream stream)
        {
            using (var wic = new WicRenderTargetBitmapImpl(PixelSize, Dpi))
            {
                using (var dc = wic.CreateDrawingContext(null))
                {
                    dc.DrawImage(
                        RefCountable.CreateUnownedNotClonable(this),
                        1,
                        new Rect(PixelSize.ToSize(Dpi.X)),
                        new Rect(PixelSize.ToSize(Dpi.X)));
                }

                wic.Save(stream);
            }
        }