diff --git a/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs b/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
index 3d567fe458..af69e75571 100644
--- a/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
+++ b/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
@@ -11,18 +11,41 @@ namespace Avalonia.Media.Imaging
///
public class Bitmap : IBitmap
{
+ ///
+ /// 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.
+ ///
+ /// The stream to read the bitmap from. This can be any supported image format.
+ /// The desired width of the resulting bitmap.
+ /// The to use should any scaling be required.
+ /// An instance of the class.
public static Bitmap DecodeToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService();
return new Bitmap(factory.LoadBitmapToWidth(stream, width, interpolationMode));
}
+ ///
+ /// 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.
+ ///
+ /// The stream to read the bitmap from. This can be any supported image format.
+ /// The desired height of the resulting bitmap.
+ /// The to use should any scaling be required.
+ /// An instance of the class.
public static Bitmap DecodeToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService();
return new Bitmap(factory.LoadBitmapToHeight(stream, height, interpolationMode));
}
+ ///
+ /// Creates a Bitmap from another Bitmap scaled to a specified size.
+ ///
+ /// The source bitmap.
+ /// The destination size.
+ /// The to use should any scaling be required.
+ /// An instance of the class.
public static Bitmap CreateScaledBitmap(Bitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService();
@@ -57,7 +80,7 @@ namespace Avalonia.Media.Imaging
{
PlatformImpl = impl.Clone();
}
-
+
///
/// Initializes a new instance of the class.
///
@@ -66,7 +89,7 @@ namespace Avalonia.Media.Imaging
{
PlatformImpl = RefCountable.Create(impl);
}
-
+
///
public virtual void Dispose()
{
diff --git a/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs b/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs
index e35d1154a1..c0ef65943a 100644
--- a/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs
+++ b/src/Avalonia.Visuals/Platform/IPlatformRenderInterface.cs
@@ -91,7 +91,7 @@ namespace Avalonia.Platform
///
/// The filename of the bitmap.
/// An .
- IBitmapImpl LoadBitmap(string fileName);
+ IBitmapImpl LoadBitmap(string fileName);
///
/// Loads a bitmap implementation from a file..
@@ -101,16 +101,20 @@ namespace Avalonia.Platform
IBitmapImpl LoadBitmap(Stream stream);
///
- /// Loads a bitmap implementation from a file..
+ /// Loads a bitmap implementation from a stream to a specified width maintaining aspect ratio.
///
- /// The stream to read the bitmap from.
+ /// The stream to read the bitmap from.
+ /// The desired width of the resulting bitmap.
+ /// The to use should resizing be required.
/// An .
IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
///
- /// Loads a bitmap implementation from a file..
+ /// Loads a bitmap implementation from a stream to a specified height maintaining aspect ratio.
///
- /// The stream to read the bitmap from.
+ /// The stream to read the bitmap from.
+ /// The desired height of the resulting bitmap.
+ /// The to use should resizing be required.
/// An .
IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality);
diff --git a/src/Skia/Avalonia.Skia/ImmutableBitmap.cs b/src/Skia/Avalonia.Skia/ImmutableBitmap.cs
index 8323eabfbb..4fc02b28e1 100644
--- a/src/Skia/Avalonia.Skia/ImmutableBitmap.cs
+++ b/src/Skia/Avalonia.Skia/ImmutableBitmap.cs
@@ -41,7 +41,7 @@ namespace Avalonia.Skia
}
public ImmutableBitmap(ImmutableBitmap src, PixelSize destinationSize, BitmapInterpolationMode interpolationMode)
- {
+ {
SKImageInfo info = new SKImageInfo(destinationSize.Width, destinationSize.Height, SKColorType.Bgra8888);
SKImage output = SKImage.Create(info);
src._image.ScalePixels(output.PeekPixels(), interpolationMode.ToSKFilterQuality());
diff --git a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
index f744b2f00a..869ca6969b 100644
--- a/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
+++ b/src/Skia/Avalonia.Skia/PlatformRenderInterface.cs
@@ -80,6 +80,7 @@ namespace Avalonia.Skia
return new StreamGeometryImpl();
}
+ ///
public IBitmapImpl LoadBitmap(string fileName)
{
using (var stream = File.OpenRead(fileName))
@@ -88,27 +89,31 @@ namespace Avalonia.Skia
}
}
+ ///
public IBitmapImpl LoadBitmap(Stream stream)
{
return new ImmutableBitmap(stream);
}
+ ///
+ public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
+ {
+ return new ImmutableBitmap(size, dpi, stride, format, data);
+ }
+
+ ///
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return new ImmutableBitmap(stream, width, true, interpolationMode);
}
+ ///
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
return new ImmutableBitmap(stream, height, false, interpolationMode);
}
///
- 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)
{
if (bitmapImpl is ImmutableBitmap ibmp)
diff --git a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs
index ef5b3255c1..fa96a5eebf 100644
--- a/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs
+++ b/src/Windows/Avalonia.Direct2D1/Direct2D1Platform.cs
@@ -181,31 +181,37 @@ namespace Avalonia.Direct2D1
public IGeometryImpl CreateRectangleGeometry(Rect rect) => new RectangleGeometryImpl(rect);
public IStreamGeometryImpl CreateStreamGeometry() => new StreamGeometryImpl();
+ ///
public IBitmapImpl LoadBitmap(string fileName)
{
return new WicBitmapImpl(fileName);
}
+ ///
public IBitmapImpl LoadBitmap(Stream stream)
{
return new WicBitmapImpl(stream);
}
+ ///
public IBitmapImpl LoadBitmapToWidth(Stream stream, int width, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
+ ///
public IBitmapImpl LoadBitmapToHeight(Stream stream, int height, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
+ ///
public IBitmapImpl ResizeBitmap(IBitmapImpl bitmapImpl, PixelSize destinationSize, BitmapInterpolationMode interpolationMode = BitmapInterpolationMode.HighQuality)
{
throw new NotImplementedException();
}
+ ///
public IBitmapImpl LoadBitmap(PixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
{
return new WicBitmapImpl(format, data, size, dpi, stride);