This commit is contained in:
Paul Betts 2013-06-30 15:40:24 -07:00
Родитель fb659182b2
Коммит c7bb092941
4 изменённых файлов: 98 добавлений и 93 удалений

Просмотреть файл

@ -1,89 +1,89 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Splat
{
public enum CompressedBitmapFormat
{
Png, Jpeg,
}
/// <summary>
/// Represents the platform-specific image loader class. Unless you are
/// testing image loading, you don't usually need to implement this.
/// </summary>
public interface IBitmapLoader
{
/// <summary>
/// Loads a bitmap from a byte stream
/// </summary>
/// <param name="sourceStream">The stream to load the image from.</param>
/// <param name="desiredWidth">The desired width of the image.</param>
/// <param name="desiredHeight">The desired height of the image.</param>
/// <returns>A future result representing the loaded image</returns>
Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight);
/// <summary>
/// Creates an empty bitmap of the specified dimensions
/// </summary>
/// <param name="width">The width of the canvas</param>
/// <param name="height">The height of the canvas</param>
/// <returns>A new image. Use ToNative() to convert this to a native bitmap</returns>
IBitmap Create(float width, float height);
}
/// <summary>
/// Represents a bitmap image that was loaded via a ViewModel. Every platform
/// provides FromNative and ToNative methods to convert this object to the
/// platform-specific versions.
/// </summary>
public interface IBitmap : IDisposable
{
/// <summary>
/// Width in pixel units (depending on platform)
/// </summary>
float Width { get; }
/// <summary>
/// Height in pixel units (depending on platform)
/// </summary>
float Height { get; }
/// <summary>
/// Saves an image to a target stream
/// </summary>
/// <param name="format">The format to save the image in.</param>
/// <param name="quality">If JPEG is specified, this is a quality
/// factor between 0.0 and 1.0f where 1.0f is the best quality.</param>
/// <param name="target">The target stream to save to.</param>
/// <returns>A signal indicating the Save has completed.</returns>
Task Save(CompressedBitmapFormat format, float quality, Stream target);
}
/// <summary>
/// This class loads and creates bitmap resources in a platform-independent
/// way.
/// </summary>
public static class BitmapLoader
{
// TODO: This needs to be improved once we move the "Detect in Unit Test
// Runner" code into Splat
static IBitmapLoader _Current;
public static IBitmapLoader Current {
get {
var ret = _Current;
if (ret == null) {
throw new Exception("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken");
}
return ret;
}
set { _Current = value; }
}
}
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Splat
{
public enum CompressedBitmapFormat
{
Png, Jpeg,
}
/// <summary>
/// Represents the platform-specific image loader class. Unless you are
/// testing image loading, you don't usually need to implement this.
/// </summary>
public interface IBitmapLoader
{
/// <summary>
/// Loads a bitmap from a byte stream
/// </summary>
/// <param name="sourceStream">The stream to load the image from.</param>
/// <param name="desiredWidth">The desired width of the image.</param>
/// <param name="desiredHeight">The desired height of the image.</param>
/// <returns>A future result representing the loaded image</returns>
Task<IBitmap> Load(Stream sourceStream, float? desiredWidth, float? desiredHeight);
/// <summary>
/// Creates an empty bitmap of the specified dimensions
/// </summary>
/// <param name="width">The width of the canvas</param>
/// <param name="height">The height of the canvas</param>
/// <returns>A new image. Use ToNative() to convert this to a native bitmap</returns>
IBitmap Create(float width, float height);
}
/// <summary>
/// Represents a bitmap image that was loaded via a ViewModel. Every platform
/// provides FromNative and ToNative methods to convert this object to the
/// platform-specific versions.
/// </summary>
public interface IBitmap : IDisposable
{
/// <summary>
/// Width in pixel units (depending on platform)
/// </summary>
float Width { get; }
/// <summary>
/// Height in pixel units (depending on platform)
/// </summary>
float Height { get; }
/// <summary>
/// Saves an image to a target stream
/// </summary>
/// <param name="format">The format to save the image in.</param>
/// <param name="quality">If JPEG is specified, this is a quality
/// factor between 0.0 and 1.0f where 1.0f is the best quality.</param>
/// <param name="target">The target stream to save to.</param>
/// <returns>A signal indicating the Save has completed.</returns>
Task Save(CompressedBitmapFormat format, float quality, Stream target);
}
/// <summary>
/// This class loads and creates bitmap resources in a platform-independent
/// way.
/// </summary>
public static class BitmapLoader
{
// TODO: This needs to be improved once we move the "Detect in Unit Test
// Runner" code into Splat
static IBitmapLoader _Current;
public static IBitmapLoader Current {
get {
var ret = _Current;
if (ret == null) {
throw new Exception("Could not find a default bitmap loader. This should never happen, your dependency resolver is broken");
}
return ret;
}
set { _Current = value; }
}
}
}

Просмотреть файл

@ -30,13 +30,17 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
@ -57,4 +61,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

Просмотреть файл

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@ -37,6 +37,7 @@
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Bitmaps.cs" />
<Compile Include="ModeDetector.cs">
<SubType>Code</SubType>
</Compile>
@ -50,4 +51,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

Просмотреть файл

@ -26,13 +26,13 @@ namespace Splat
source.EndInit();
source.Freeze();
return new BitmapSourceBitmap(source);
return (IBitmap) new BitmapSourceBitmap(source);
});
}
public IBitmap Create(float width, float height)
{
return new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Default, null));
return (IBitmap) new BitmapSourceBitmap(new WriteableBitmap((int)width, (int)height, 96, 96, PixelFormats.Default, null));
}
}