diff --git a/src/Gtk/Perspex.Cairo/CairoPlatform.cs b/src/Gtk/Perspex.Cairo/CairoPlatform.cs
index b6d14e60a1..6105ef3046 100644
--- a/src/Gtk/Perspex.Cairo/CairoPlatform.cs
+++ b/src/Gtk/Perspex.Cairo/CairoPlatform.cs
@@ -10,6 +10,7 @@ using Splat;
namespace Perspex.Cairo
{
+ using System.IO;
using global::Cairo;
public class CairoPlatform : IPlatformRenderInterface
@@ -60,6 +61,11 @@ namespace Perspex.Cairo
return new BitmapImpl(result);
}
+ public IBitmapImpl LoadBitmap(Stream stream)
+ {
+ throw new NotImplementedException();
+ }
+
private Pango.Context GetPangoContext(IPlatformHandle handle)
{
switch (handle.HandleDescriptor)
diff --git a/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs b/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs
index 64872d3ada..92ec2ac1b9 100644
--- a/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs
+++ b/src/Perspex.SceneGraph/Media/Imaging/Bitmap.cs
@@ -1,6 +1,7 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
+using System.IO;
using Perspex.Platform;
using Splat;
@@ -21,6 +22,16 @@ namespace Perspex.Media.Imaging
PlatformImpl = factory.LoadBitmap(fileName);
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The stream to read the bitmap from.
+ public Bitmap(Stream stream)
+ {
+ IPlatformRenderInterface factory = Locator.Current.GetService();
+ PlatformImpl = factory.LoadBitmap(stream);
+ }
+
///
/// Initializes a new instance of the class.
///
diff --git a/src/Perspex.SceneGraph/Platform/IPlatformRenderInterface.cs b/src/Perspex.SceneGraph/Platform/IPlatformRenderInterface.cs
index a7ce8e2abf..ca40ec8137 100644
--- a/src/Perspex.SceneGraph/Platform/IPlatformRenderInterface.cs
+++ b/src/Perspex.SceneGraph/Platform/IPlatformRenderInterface.cs
@@ -1,6 +1,7 @@
// Copyright (c) The Perspex Project. All rights reserved.
// Licensed under the MIT license. See licence.md file in the project root for full license information.
+using System.IO;
using Perspex.Media;
namespace Perspex.Platform
@@ -65,5 +66,12 @@ namespace Perspex.Platform
/// The filename of the bitmap.
/// An .
IBitmapImpl LoadBitmap(string fileName);
+
+ ///
+ /// Loads a bitmap implementation from a file..
+ ///
+ /// The stream to read the bitmap from.
+ /// An .
+ IBitmapImpl LoadBitmap(Stream stream);
}
}
diff --git a/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs b/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs
index 0d04bf1994..31b0ff34a1 100644
--- a/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs
+++ b/src/Windows/Perspex.Direct2D1/Direct2D1Platform.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license. See licence.md file in the project root for full license information.
using System;
+using System.IO;
using Perspex.Direct2D1.Media;
using Perspex.Media;
using Perspex.Platform;
@@ -72,5 +73,10 @@ namespace Perspex.Direct2D1
{
return new BitmapImpl(s_imagingFactory, fileName);
}
+
+ public IBitmapImpl LoadBitmap(Stream stream)
+ {
+ return new BitmapImpl(s_imagingFactory, stream);
+ }
}
}
diff --git a/src/Windows/Perspex.Direct2D1/Media/Imaging/BitmapImpl.cs b/src/Windows/Perspex.Direct2D1/Media/Imaging/BitmapImpl.cs
index e5347cc5d6..4572c09850 100644
--- a/src/Windows/Perspex.Direct2D1/Media/Imaging/BitmapImpl.cs
+++ b/src/Windows/Perspex.Direct2D1/Media/Imaging/BitmapImpl.cs
@@ -32,6 +32,21 @@ namespace Perspex.Direct2D1.Media
}
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The WIC imaging factory to use.
+ /// The stream to read the bitmap from.
+ public BitmapImpl(ImagingFactory factory, Stream stream)
+ {
+ _factory = factory;
+
+ using (BitmapDecoder decoder = new BitmapDecoder(factory, stream, DecodeOptions.CacheOnLoad))
+ {
+ WicImpl = new Bitmap(factory, decoder.GetFrame(0), BitmapCreateCacheOption.CacheOnLoad);
+ }
+ }
+
///
/// Initializes a new instance of the class.
///