WinFormsWin32Platform.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using Avalonia.Platform;
  8. namespace Avalonia.Win32
  9. {
  10. partial class Win32Platform
  11. {
  12. public IWindowIconImpl LoadIcon(string fileName)
  13. {
  14. using (var stream = File.OpenRead(fileName))
  15. {
  16. return CreateImpl(stream);
  17. }
  18. }
  19. public IWindowIconImpl LoadIcon(Stream stream)
  20. {
  21. return CreateImpl(stream);
  22. }
  23. public IWindowIconImpl LoadIcon(IBitmapImpl bitmap)
  24. {
  25. using (var memoryStream = new MemoryStream())
  26. {
  27. bitmap.Save(memoryStream);
  28. return new IconImpl(new System.Drawing.Bitmap(memoryStream));
  29. }
  30. }
  31. private static IconImpl CreateImpl(Stream stream)
  32. {
  33. try
  34. {
  35. return new IconImpl(new System.Drawing.Icon(stream));
  36. }
  37. catch (ArgumentException)
  38. {
  39. return new IconImpl(new System.Drawing.Bitmap(stream));
  40. }
  41. }
  42. }
  43. }