LayerGenerator.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using PixiEditorDotNetCore3.Models.Tools;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. namespace PixiEditorDotNetCore3.Models
  13. {
  14. public static class LayerGenerator
  15. {
  16. /// <summary>
  17. /// Generating useable layer with image and bitmap
  18. /// </summary>
  19. /// <param name="imageWidth">Width of layer.</param>
  20. /// <param name="imageHeight">Height of layer.</param>
  21. /// <returns></returns>
  22. public static Layer Generate(int imageWidth, int imageHeight)
  23. {
  24. return new Layer(GenerateBitmap(imageWidth, imageHeight));
  25. }
  26. public static LightLayer GenerateWithByteArray(int width, int height)
  27. {
  28. WriteableBitmap bitmap = GenerateBitmap(width, height);
  29. return new LightLayer(bitmap.ToByteArray(), height, width);
  30. }
  31. /// <summary>
  32. /// Generates bitmap ready to work with
  33. /// </summary>
  34. /// <param name="bitmapWidth">Width of bitmap.</param>
  35. /// <param name="imageHeight">Height of bitmap.</param>
  36. /// <returns></returns>
  37. private static WriteableBitmap GenerateBitmap(int bitmapWidth, int imageHeight)
  38. {
  39. WriteableBitmap bitmap = BitmapFactory.New(bitmapWidth, imageHeight);
  40. bitmap.Clear(Colors.Transparent);
  41. return bitmap;
  42. }
  43. }
  44. }