WritableWicBitmapImpl.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Avalonia.Platform;
  7. using SharpDX.WIC;
  8. using PixelFormat = Avalonia.Platform.PixelFormat;
  9. namespace Avalonia.Direct2D1.Media.Imaging
  10. {
  11. class WritableWicBitmapImpl : WicBitmapImpl, IWritableBitmapImpl
  12. {
  13. public WritableWicBitmapImpl(ImagingFactory factory, int width, int height, PixelFormat? pixelFormat)
  14. : base(factory, width, height, pixelFormat)
  15. {
  16. }
  17. class LockedBitmap : ILockedFramebuffer
  18. {
  19. private readonly BitmapLock _lock;
  20. private readonly PixelFormat _format;
  21. public LockedBitmap(BitmapLock l, PixelFormat format)
  22. {
  23. _lock = l;
  24. _format = format;
  25. }
  26. public void Dispose()
  27. {
  28. _lock.Dispose();
  29. }
  30. public IntPtr Address => _lock.Data.DataPointer;
  31. public int Width => _lock.Size.Width;
  32. public int Height => _lock.Size.Height;
  33. public int RowBytes => _lock.Stride;
  34. public Vector Dpi { get; } = new Vector(96, 96);
  35. public PixelFormat Format => _format;
  36. }
  37. public ILockedFramebuffer Lock() => new LockedBitmap(WicImpl.Lock(BitmapLockFlags.Write), PixelFormat.Value);
  38. }
  39. }