diff --git a/src/Gtk/Perspex.Cairo/CairoPlatform.cs b/src/Gtk/Perspex.Cairo/CairoPlatform.cs index 6105ef3046..5ddfe1eab0 100644 --- a/src/Gtk/Perspex.Cairo/CairoPlatform.cs +++ b/src/Gtk/Perspex.Cairo/CairoPlatform.cs @@ -25,7 +25,7 @@ namespace Perspex.Cairo public IBitmapImpl CreateBitmap(int width, int height) { - return new BitmapImpl(new ImageSurface(Format.Argb32, width, height)); + return new BitmapImpl(new Gdk.Pixbuf(Gdk.Colorspace.Rgb, true, 32, width, height)); } public IFormattedTextImpl CreateFormattedText( @@ -57,13 +57,16 @@ namespace Perspex.Cairo public IBitmapImpl LoadBitmap(string fileName) { - ImageSurface result = new ImageSurface(fileName); - return new BitmapImpl(result); + var pixbuf = new Gdk.Pixbuf(fileName); + + return new BitmapImpl(pixbuf); } public IBitmapImpl LoadBitmap(Stream stream) { - throw new NotImplementedException(); + var pixbuf = new Gdk.Pixbuf(stream); + + return new BitmapImpl(pixbuf); } private Pango.Context GetPangoContext(IPlatformHandle handle) diff --git a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs index c01d1f1ac3..4c99590cb6 100644 --- a/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs +++ b/src/Gtk/Perspex.Cairo/Media/DrawingContext.cs @@ -63,7 +63,7 @@ namespace Perspex.Cairo.Media _context.Save(); _context.Scale(scaleX, scaleY); - _context.SetSourceSurface(impl.Surface, (int)sourceRect.X, (int)sourceRect.Y); + Gdk.CairoHelper.SetSourcePixbuf(_context, impl.Surface, (int)sourceRect.X, (int)sourceRect.Y); _context.Rectangle(sourceRect.ToCairo()); _context.Fill(); _context.Restore(); diff --git a/src/Gtk/Perspex.Cairo/Media/Imaging/BitmapImpl.cs b/src/Gtk/Perspex.Cairo/Media/Imaging/BitmapImpl.cs index 5748790626..4abecba6c6 100644 --- a/src/Gtk/Perspex.Cairo/Media/Imaging/BitmapImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/Imaging/BitmapImpl.cs @@ -10,22 +10,24 @@ namespace Perspex.Cairo.Media.Imaging public class BitmapImpl : IBitmapImpl { - public BitmapImpl(Cairo.ImageSurface surface) + public BitmapImpl(Gdk.Pixbuf pixbuf) { - Surface = surface; + Surface = pixbuf; } public int PixelWidth => Surface.Width; public int PixelHeight => Surface.Height; - public Cairo.ImageSurface Surface + public Gdk.Pixbuf Surface { - get; } + get; + } public void Save(string fileName) { - Surface.WriteToPng(fileName); + // TODO: Test + Surface.Save(fileName, "png"); } } } diff --git a/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs b/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs index 51cdc645ef..8c017d9cfd 100644 --- a/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs +++ b/src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs @@ -8,23 +8,38 @@ namespace Perspex.Cairo.Media.Imaging { using Cairo = global::Cairo; - public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl + public class RenderTargetBitmapImpl : IRenderTargetBitmapImpl { public RenderTargetBitmapImpl( - Cairo.ImageSurface surface) - : base(surface) + Cairo.ImageSurface surface) { + } + public int PixelWidth => Surface.Width; + + public int PixelHeight => Surface.Height; + public void Dispose() { Surface.Dispose(); } + + public Cairo.ImageSurface Surface + { + get; + } + public void Render(IVisual visual) { Renderer renderer = new Renderer(Surface); renderer.Render(visual, new PlatformHandle(IntPtr.Zero, "RTB")); } + + public void Save(string fileName) + { + Surface.WriteToPng(fileName); + } } } \ No newline at end of file