27 changed files with 237 additions and 21 deletions
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Avalonia.Platform; |
||||
|
|
||||
|
namespace Avalonia.Media.Imaging |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Holds a writable bitmap image.
|
||||
|
/// </summary>
|
||||
|
public class WritableBitmap : Bitmap |
||||
|
{ |
||||
|
public WritableBitmap(int width, int height, PixelFormat? format = null) |
||||
|
: base(AvaloniaLocator.Current.GetService<IPlatformRenderInterface>().CreateWritableBitmap(width, height, format)) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public ILockedFramebuffer Lock() => ((IWritableBitmapImpl) PlatformImpl).Lock(); |
||||
|
} |
||||
|
} |
||||
@ -1,7 +1,6 @@ |
|||||
using System; |
using System; |
||||
using Avalonia.Platform; |
|
||||
|
|
||||
namespace Avalonia.Controls.Platform.Surfaces |
namespace Avalonia.Platform |
||||
{ |
{ |
||||
public interface ILockedFramebuffer : IDisposable |
public interface ILockedFramebuffer : IDisposable |
||||
{ |
{ |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Avalonia.Platform |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Defines the platform-specific interface for a <see cref="Avalonia.Media.Imaging.WritableBitmap"/>.
|
||||
|
/// </summary>
|
||||
|
public interface IWritableBitmapImpl : IBitmapImpl |
||||
|
{ |
||||
|
ILockedFramebuffer Lock(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using Avalonia.Platform; |
||||
|
using SharpDX.WIC; |
||||
|
using PixelFormat = Avalonia.Platform.PixelFormat; |
||||
|
|
||||
|
namespace Avalonia.Direct2D1.Media.Imaging |
||||
|
{ |
||||
|
class WritableWicBitmapImpl : WicBitmapImpl, IWritableBitmapImpl |
||||
|
{ |
||||
|
public WritableWicBitmapImpl(ImagingFactory factory, int width, int height, PixelFormat? pixelFormat) |
||||
|
: base(factory, width, height, pixelFormat) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
class LockedBitmap : ILockedFramebuffer |
||||
|
{ |
||||
|
private readonly BitmapLock _lock; |
||||
|
private readonly PixelFormat _format; |
||||
|
|
||||
|
public LockedBitmap(BitmapLock l, PixelFormat format) |
||||
|
{ |
||||
|
_lock = l; |
||||
|
_format = format; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
public void Dispose() |
||||
|
{ |
||||
|
_lock.Dispose(); |
||||
|
} |
||||
|
|
||||
|
public IntPtr Address => _lock.Data.DataPointer; |
||||
|
public int Width => _lock.Size.Width; |
||||
|
public int Height => _lock.Size.Height; |
||||
|
public int RowBytes => _lock.Stride; |
||||
|
public Size Dpi { get; } = new Size(96, 96); |
||||
|
public PixelFormat Format => _format; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
public ILockedFramebuffer Lock() => new LockedBitmap(WicImpl.Lock(BitmapLockFlags.Write), PixelFormat.Value); |
||||
|
} |
||||
|
} |
||||
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 144 KiB |
|
After Width: | Height: | Size: 89 KiB |
Loading…
Reference in new issue