Importer.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. using PixiEditor.Helpers;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Media.Imaging;
  8. using System.Windows.Media;
  9. namespace PixiEditorDotNetCore3.Models
  10. {
  11. public class Importer : NotifyableObject
  12. {
  13. /// <summary>
  14. /// Imports image from path and resizes it to given dimensions
  15. /// </summary>
  16. /// <param name="path">Path of image.</param>
  17. /// <param name="width">New width of image.</param>
  18. /// <param name="height">New height of image.</param>
  19. /// <returns></returns>
  20. public static WriteableBitmap ImportImage(string path, int width, int height)
  21. {
  22. Uri uri = new Uri(path);
  23. BitmapImage bitmap = new BitmapImage();
  24. bitmap.BeginInit();
  25. bitmap.UriSource = uri;
  26. bitmap.DecodePixelWidth = width;
  27. bitmap.DecodePixelHeight = height;
  28. bitmap.EndInit();
  29. return new WriteableBitmap(bitmap);
  30. }
  31. }
  32. }