LayerGenerator.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using PixiEditor.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 PixiEditor.Models.Layers
  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. bitmap.Lock();
  30. byte[] byteArray = bitmap.ToByteArray();
  31. bitmap.Unlock();
  32. return new LightLayer(byteArray, height, width);
  33. }
  34. /// <summary>
  35. /// Generates bitmap ready to work with
  36. /// </summary>
  37. /// <param name="bitmapWidth">Width of bitmap.</param>
  38. /// <param name="imageHeight">Height of bitmap.</param>
  39. /// <returns></returns>
  40. private static WriteableBitmap GenerateBitmap(int bitmapWidth, int imageHeight)
  41. {
  42. WriteableBitmap bitmap = BitmapFactory.New(bitmapWidth, imageHeight);
  43. bitmap.Clear(System.Windows.Media.Colors.Transparent);
  44. return bitmap;
  45. }
  46. }
  47. }