// -----------------------------------------------------------------------
//
// Copyright 2013 MIT Licence. See licence.md for more information.
//
// -----------------------------------------------------------------------
namespace Perspex.Media.Imaging
{
using Perspex.Platform;
using Splat;
///
/// Holds a bitmap image.
///
public class Bitmap : IBitmap
{
///
/// Initializes a new instance of the class.
///
/// The filename of the bitmap.
public Bitmap(string fileName)
{
IPlatformRenderInterface factory = Locator.Current.GetService();
this.PlatformImpl = factory.LoadBitmap(fileName);
}
///
/// Initializes a new instance of the class.
///
/// The width of the bitmap, in pixels.
/// The height of the bitmap, in pixels.
public Bitmap(int width, int height)
{
IPlatformRenderInterface factory = Locator.Current.GetService();
this.PlatformImpl = factory.CreateBitmap(width, height);
}
///
/// Initializes a new instance of the class.
///
/// A platform-specific bitmap implementation.
protected Bitmap(IBitmapImpl impl)
{
this.PlatformImpl = impl;
}
///
/// Gets the width of the bitmap, in pixels.
///
public int PixelWidth
{
get { return this.PlatformImpl.PixelWidth; }
}
///
/// Gets the height of the bitmap, in pixels.
///
public int PixelHeight
{
get { return this.PlatformImpl.PixelHeight; }
}
///
/// Gets the platform-specific bitmap implementation.
///
public IBitmapImpl PlatformImpl
{
get;
private set;
}
///
/// Saves the bitmap to a file.
///
/// The filename.
public void Save(string fileName)
{
this.PlatformImpl.Save(fileName);
}
}
}