RenderTargetBitmapImpl.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (c) The Perspex Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using Perspex.Media;
  5. using Perspex.Platform;
  6. using Perspex.Rendering;
  7. using SharpDX.Direct2D1;
  8. using SharpDX.WIC;
  9. namespace Perspex.Direct2D1.Media
  10. {
  11. public class RenderTargetBitmapImpl : BitmapImpl, IRenderTargetBitmapImpl, IDisposable
  12. {
  13. private readonly WicRenderTarget _target;
  14. public RenderTargetBitmapImpl(
  15. ImagingFactory imagingFactory,
  16. Factory d2dFactory,
  17. int width,
  18. int height)
  19. : base(imagingFactory, width, height)
  20. {
  21. var props = new RenderTargetProperties
  22. {
  23. DpiX = 96,
  24. DpiY = 96,
  25. };
  26. _target = new WicRenderTarget(
  27. d2dFactory,
  28. WicImpl,
  29. props);
  30. }
  31. public override void Dispose()
  32. {
  33. _target.Dispose();
  34. base.Dispose();
  35. }
  36. public Perspex.Media.DrawingContext CreateDrawingContext() => new RenderTarget(_target).CreateDrawingContext();
  37. }
  38. }