Browse Source

Merge pull request #137 from ncarrillo/cairo-bitmap-stream

Added support for loading Bitmaps from a Stream for Gtk/Cairo
pull/140/head
Steven Kirk 11 years ago
parent
commit
afc44d933b
  1. 11
      src/Gtk/Perspex.Cairo/CairoPlatform.cs
  2. 2
      src/Gtk/Perspex.Cairo/Media/DrawingContext.cs
  3. 12
      src/Gtk/Perspex.Cairo/Media/Imaging/BitmapImpl.cs
  4. 21
      src/Gtk/Perspex.Cairo/Media/Imaging/RenderTargetBitmapImpl.cs

11
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)

2
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();

12
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");
}
}
}

21
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);
}
}
}
Loading…
Cancel
Save