ImageUtility.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System.Drawing;
  2. using System.Windows.Media.Imaging;
  3. using System.Drawing.Imaging;
  4. namespace ConstRectCropImage
  5. {
  6. /// <summary>
  7. /// 图像处理工具类
  8. /// </summary>
  9. public static class ImageUtility
  10. {
  11. public static BitmapImage BitmapToBitmapImage(Bitmap img)
  12. {
  13. BitmapImage bmpimg = new BitmapImage();
  14. using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
  15. {
  16. img.Save(ms, ImageFormat.Png);
  17. bmpimg.BeginInit();
  18. bmpimg.StreamSource = ms;
  19. bmpimg.CacheOption = BitmapCacheOption.OnLoad;
  20. bmpimg.EndInit();
  21. bmpimg.Freeze();
  22. ms.Dispose();
  23. }
  24. return bmpimg;
  25. }
  26. }
  27. /// <summary>
  28. /// 图像裁切时保存的信息
  29. /// </summary>
  30. public class ImgInfoForSegEntity
  31. {
  32. /// <summary>
  33. /// 图片ID
  34. /// </summary>
  35. public string ImgId { get; set; } = string.Empty;
  36. /// <summary>
  37. /// 图片路径
  38. /// </summary>
  39. public string ImgLocalPath { get; set; } = string.Empty;
  40. /// <summary>
  41. /// 裁切是否成功
  42. /// </summary>
  43. public bool SegSucceed { get; set; } = false;
  44. /// <summary>
  45. /// 裁切后,图像左上点在原始图像上的像素坐标x
  46. /// </summary>
  47. public int Left { get; set; } = 0;
  48. /// <summary>
  49. /// 裁切后,图像右下点在原始图像上的像素坐标x
  50. /// </summary>
  51. public int Right { get; set; } = 0;
  52. /// <summary>
  53. /// 裁切后,图像左上点在原始图像上的像素坐标y
  54. /// </summary>
  55. public int Top { get; set; } = 0;
  56. /// <summary>
  57. /// 裁切后,图像右下点在原始图像上的像素坐标y
  58. /// </summary>
  59. public int Bottom { get; set; } = 0;
  60. }
  61. }