|
|
@ -1,5 +1,8 @@ |
|
|
using System; |
|
|
using System; |
|
|
|
|
|
using System.IO; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
using Avalonia.Platform; |
|
|
using Avalonia.Platform; |
|
|
|
|
|
using Avalonia.Visuals.Media.Imaging; |
|
|
|
|
|
|
|
|
namespace Avalonia.Media.Imaging |
|
|
namespace Avalonia.Media.Imaging |
|
|
{ |
|
|
{ |
|
|
@ -34,8 +37,50 @@ namespace Avalonia.Media.Imaging |
|
|
{ |
|
|
{ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private WriteableBitmap(IWriteableBitmapImpl impl) : base(impl) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ILockedFramebuffer Lock() => ((IWriteableBitmapImpl) PlatformImpl.Item).Lock(); |
|
|
public ILockedFramebuffer Lock() => ((IWriteableBitmapImpl) PlatformImpl.Item).Lock(); |
|
|
|
|
|
|
|
|
|
|
|
public static WriteableBitmap Decode(Stream stream) |
|
|
|
|
|
{ |
|
|
|
|
|
var ri = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); |
|
|
|
|
|
|
|
|
|
|
|
return new WriteableBitmap(ri.LoadWriteableBitmap(stream)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Loads a WriteableBitmap 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) |
|
|
|
|
|
{ |
|
|
|
|
|
var ri = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); |
|
|
|
|
|
|
|
|
|
|
|
return new WriteableBitmap(ri.LoadWriteableBitmapToWidth(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) |
|
|
|
|
|
{ |
|
|
|
|
|
var ri = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); |
|
|
|
|
|
|
|
|
|
|
|
return new WriteableBitmap(ri.LoadWriteableBitmapToHeight(stream, height, interpolationMode)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private static IBitmapImpl CreatePlatformImpl(PixelSize size, in Vector dpi, PixelFormat? format, AlphaFormat? alphaFormat) |
|
|
private static IBitmapImpl CreatePlatformImpl(PixelSize size, in Vector dpi, PixelFormat? format, AlphaFormat? alphaFormat) |
|
|
{ |
|
|
{ |
|
|
var ri = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); |
|
|
var ri = AvaloniaLocator.Current.GetService<IPlatformRenderInterface>(); |
|
|
|