Browse Source

Add documentation.

pull/3890/head
Dan Walmsley 7 years ago
parent
commit
ac65b4e717
  1. 27
      src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
  2. 14
      src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs
  3. 2
      src/Skia/Avalonia.Skia/ImmutableBitmap.cs
  4. 15
      src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
  5. 6
      src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs

27
src/Avalonia.Visuals/Media/Imaging/Bitmap.cs

@ -11,18 +11,41 @@ namespace Avalonia.Media.Imaging
/// </summary> /// </summary>
public class Bitmap : IBitmap public class Bitmap : IBitmap
{ {
/// <summary>
/// Loads a Bitmap from a stream and decodes at the desired width. Aspect ratio is maintained.
/// This is more efficient than loading and then resizing.
/// </summary>
/// <param name="stream">The stream to read the bitmap from. This can be any supported image format.</param>
/// <param name="width">The desired width of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should any scaling be required.</param>
/// <returns>An instance of the <see cref="Bitmap"/> class.</returns>
public static Bitmap DecodeToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public static Bitmap DecodeToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
return new Bitmap(factory.LoadBitmapToWidth(stream, width, interpolationMode)); return new Bitmap(factory.LoadBitmapToWidth(stream, width, interpolationMode));
} }
/// <summary>
/// Loads a Bitmap from a stream and decodes at the desired height. Aspect ratio is maintained.
/// This is more efficient than loading and then resizing.
/// </summary>
/// <param name="stream">The stream to read the bitmap from. This can be any supported image format.</param>
/// <param name="height">The desired height of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should any scaling be required.</param>
/// <returns>An instance of the <see cref="Bitmap"/> class.</returns>
public static Bitmap DecodeToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public static Bitmap DecodeToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
return new Bitmap(factory.LoadBitmapToHeight(stream, height, interpolationMode)); return new Bitmap(factory.LoadBitmapToHeight(stream, height, interpolationMode));
} }
/// <summary>
/// Creates a Bitmap from another Bitmap scaled to a specified size.
/// </summary>
/// <param name="src">The source bitmap.</param>
/// <param name="destinationSize">The destination size.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should any scaling be required.</param>
/// <returns>An instance of the <see cref="Bitmap"/> class.</returns>
public static Bitmap CreateScaledBitmap(Bitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public static Bitmap CreateScaledBitmap(Bitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>();
@ -57,7 +80,7 @@ namespace Avalonia.Media.Imaging
{ {
PlatformImpl = impl.Clone(); PlatformImpl = impl.Clone();
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Bitmap"/> class. /// Initializes a new instance of the <see cref="Bitmap"/> class.
/// </summary> /// </summary>
@ -66,7 +89,7 @@ namespace Avalonia.Media.Imaging
{ {
PlatformImpl = RefCountable.Create(impl); PlatformImpl = RefCountable.Create(impl);
} }
/// <inheritdoc/> /// <inheritdoc/>
public virtual void Dispose() public virtual void Dispose()
{ {

14
src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs

@ -91,7 +91,7 @@ namespace Avalonia.Platform
/// </summary> /// </summary>
/// <param name="fileName">The filename of the bitmap.</param> /// <param name="fileName">The filename of the bitmap.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns> /// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmap(string fileName); IBitmapImpl LoadBitmap(string fileName);
/// <summary> /// <summary>
/// Loads a bitmap implementation from a file.. /// Loads a bitmap implementation from a file..
@ -101,16 +101,20 @@ namespace Avalonia.Platform
IBitmapImpl LoadBitmap(Stream stream); IBitmapImpl LoadBitmap(Stream stream);
/// <summary> /// <summary>
/// Loads a bitmap implementation from a file.. /// Loads a bitmap implementation from a stream to a specified width maintaining aspect ratio.
/// </summary> /// </summary>
/// <param name="stream">The stream to read the bitmap from.</param> /// <param name="stream">The stream to read the bitmap from.</param>
/// <param name="width">The desired width of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns> /// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality); IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
/// <summary> /// <summary>
/// Loads a bitmap implementation from a file.. /// Loads a bitmap implementation from a stream to a specified height maintaining aspect ratio.
/// </summary> /// </summary>
/// <param name="stream">The stream to read the bitmap from.</param> /// <param name="stream">The stream to read the bitmap from.</param>
/// <param name="height">The desired height of the resulting bitmap.</param>
/// <param name="interpolationMode">The <see cref="BitmapInterpolationMode"/> to use should resizing be required.</param>
/// <returns>An <see cref="IBitmapImpl"/>.</returns> /// <returns>An <see cref="IBitmapImpl"/>.</returns>
IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality); IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);

2
src/Skia/Avalonia.Skia/ImmutableBitmap.cs

@ -41,7 +41,7 @@ namespace Avalonia.Skia
} }
public ImmutableBitmap(ImmutableBitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode) public ImmutableBitmap(ImmutableBitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode)
{ {
SKImageInfo info = new SKImageInfo(destinationSize.Width, destinationSize.Height, SKColorType.Bgra8888); SKImageInfo info = new SKImageInfo(destinationSize.Width, destinationSize.Height, SKColorType.Bgra8888);
SKImage output = SKImage.Create(info); SKImage output = SKImage.Create(info);
src._image.ScalePixels(output.PeekPixels(), interpolationMode.ToSKFilterQuality()); src._image.ScalePixels(output.PeekPixels(), interpolationMode.ToSKFilterQuality());

15
src/Skia/Avalonia.Skia/PlatformRenderInterface.cs

@ -80,6 +80,7 @@ namespace Avalonia.Skia
return new StreamGeometryImpl(); return new StreamGeometryImpl();
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(string fileName) public IBitmapImpl LoadBitmap(string fileName)
{ {
using (var stream = File.OpenRead(fileName)) using (var stream = File.OpenRead(fileName))
@ -88,27 +89,31 @@ namespace Avalonia.Skia
} }
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(Stream stream) public IBitmapImpl LoadBitmap(Stream stream)
{ {
return new ImmutableBitmap(stream); return new ImmutableBitmap(stream);
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
{
return new ImmutableBitmap(size, dpi, stride, format, data);
}
/// <inheritdoc />
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
return new ImmutableBitmap(stream, width, true, interpolationMode); return new ImmutableBitmap(stream, width, true, interpolationMode);
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
return new ImmutableBitmap(stream, height, false, interpolationMode); return new ImmutableBitmap(stream, height, false, interpolationMode);
} }
/// <inheritdoc /> /// <inheritdoc />
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
{
return new ImmutableBitmap(size, dpi, stride, format, data);
}
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
if (bitmapImpl is ImmutableBitmap ibmp) if (bitmapImpl is ImmutableBitmap ibmp)

6
src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs

@ -181,31 +181,37 @@ namespace Avalonia.Direct2D1
public IGeometryImpl CreateRectangleGeometry(Rect rect) => new RectangleGeometryImpl(rect); public IGeometryImpl CreateRectangleGeometry(Rect rect) => new RectangleGeometryImpl(rect);
public IStreamGeometryImpl CreateStreamGeometry() => new StreamGeometryImpl(); public IStreamGeometryImpl CreateStreamGeometry() => new StreamGeometryImpl();
/// <inheritdoc />
public IBitmapImpl LoadBitmap(string fileName) public IBitmapImpl LoadBitmap(string fileName)
{ {
return new WicBitmapImpl(fileName); return new WicBitmapImpl(fileName);
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(Stream stream) public IBitmapImpl LoadBitmap(Stream stream)
{ {
return new WicBitmapImpl(stream); return new WicBitmapImpl(stream);
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <inheritdoc />
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality) public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
/// <inheritdoc />
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride) public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
{ {
return new WicBitmapImpl(format, data, size, dpi, stride); return new WicBitmapImpl(format, data, size, dpi, stride);

Loading…
Cancel
Save