|
|
|
@ -11,12 +11,20 @@ namespace Perspex.Direct2D1.Media |
|
|
|
using Perspex.Platform; |
|
|
|
using SharpDX.WIC; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A Direct2D implementation of a <see cref="Perspex.Media.Imaging.Bitmap"/>.
|
|
|
|
/// </summary>
|
|
|
|
public class BitmapImpl : IBitmapImpl |
|
|
|
{ |
|
|
|
private ImagingFactory factory; |
|
|
|
|
|
|
|
private SharpDX.Direct2D1.Bitmap direct2D; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="BitmapImpl"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="factory">The WIC imaging factory to use.</param>
|
|
|
|
/// <param name="fileName">The filename of the bitmap to load.</param>
|
|
|
|
public BitmapImpl(ImagingFactory factory, string fileName) |
|
|
|
{ |
|
|
|
this.factory = factory; |
|
|
|
@ -27,6 +35,12 @@ namespace Perspex.Direct2D1.Media |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="BitmapImpl"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="factory">The WIC imaging factory to use.</param>
|
|
|
|
/// <param name="width">The width of the bitmap.</param>
|
|
|
|
/// <param name="height">The height of the bitmap.</param>
|
|
|
|
public BitmapImpl(ImagingFactory factory, int width, int height) |
|
|
|
{ |
|
|
|
this.factory = factory; |
|
|
|
@ -38,22 +52,36 @@ namespace Perspex.Direct2D1.Media |
|
|
|
BitmapCreateCacheOption.CacheOnLoad); |
|
|
|
} |
|
|
|
|
|
|
|
public int PixelHeight |
|
|
|
/// <summary>
|
|
|
|
/// Gets the width of the bitmap, in pixels.
|
|
|
|
/// </summary>
|
|
|
|
public int PixelWidth |
|
|
|
{ |
|
|
|
get { return this.WicImpl.Size.Width; } |
|
|
|
get { return this.WicImpl.Size.Height; } |
|
|
|
} |
|
|
|
|
|
|
|
public int PixelWidth |
|
|
|
/// <summary>
|
|
|
|
/// Gets the height of the bitmap, in pixels.
|
|
|
|
/// </summary>
|
|
|
|
public int PixelHeight |
|
|
|
{ |
|
|
|
get { return this.WicImpl.Size.Height; } |
|
|
|
get { return this.WicImpl.Size.Width; } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the WIC implementation of the bitmap.
|
|
|
|
/// </summary>
|
|
|
|
public Bitmap WicImpl |
|
|
|
{ |
|
|
|
get; |
|
|
|
private set; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets a Direct2D bitmap to use on the specified render target.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="renderTarget">The render target.</param>
|
|
|
|
/// <returns>The Direct2D bitmap.</returns>
|
|
|
|
public SharpDX.Direct2D1.Bitmap GetDirect2DBitmap(SharpDX.Direct2D1.RenderTarget renderTarget) |
|
|
|
{ |
|
|
|
if (this.direct2D == null) |
|
|
|
@ -66,6 +94,10 @@ namespace Perspex.Direct2D1.Media |
|
|
|
return this.direct2D; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Saves the bitmap to a file.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="fileName">The filename.</param>
|
|
|
|
public void Save(string fileName) |
|
|
|
{ |
|
|
|
if (Path.GetExtension(fileName) != ".png") |
|
|
|
|