BitmapImpl.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright (c) The Avalonia 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 System.IO;
  5. using Avalonia.Platform;
  6. using SharpDX.WIC;
  7. namespace Avalonia.Direct2D1.Media
  8. {
  9. using SharpDX.Direct2D1;
  10. public abstract class BitmapImpl : IBitmapImpl, IDisposable
  11. {
  12. public BitmapImpl(ImagingFactory imagingFactory)
  13. {
  14. WicImagingFactory = imagingFactory;
  15. }
  16. public ImagingFactory WicImagingFactory { get; }
  17. public abstract int PixelWidth { get; }
  18. public abstract int PixelHeight { get; }
  19. public abstract OptionalDispose<Bitmap> GetDirect2DBitmap(RenderTarget target);
  20. public void Save(string fileName)
  21. {
  22. if (Path.GetExtension(fileName) != ".png")
  23. {
  24. // Yeah, we need to support other formats.
  25. throw new NotSupportedException("Use PNG, stoopid.");
  26. }
  27. using (FileStream s = new FileStream(fileName, FileMode.Create))
  28. {
  29. Save(s);
  30. }
  31. }
  32. public abstract void Save(Stream stream);
  33. public virtual void Dispose()
  34. {
  35. }
  36. }
  37. }