HomePageConverterImgViewModel.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using ComPDFKit_Conversion.Converter;
  2. using ComPDFKit_Conversion.Options;
  3. using Microsoft.Office.Interop.Word;
  4. using PDF_Master.Model;
  5. using Prism.Commands;
  6. using Prism.Mvvm;
  7. using Prism.Regions;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Reflection;
  12. namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing.HomePageConverter
  13. {
  14. public class HomePageConverterImgViewModel : BindableBase, INavigationAware
  15. {
  16. #region 参数和属性
  17. public List<string> ImageTypeFamily { set; get; } = new List<string>();
  18. public HomePageConverterDialogViewModel homePageConverterDialogViewModel { get; set; }
  19. private void SetImageTypeOrigin()
  20. {
  21. this.ImageTypeFamily.Add("JPEG");
  22. this.ImageTypeFamily.Add("JPG");
  23. this.ImageTypeFamily.Add("PNG");
  24. this.ImageTypeFamily.Add("GIF");
  25. this.ImageTypeFamily.Add("TIFF");
  26. this.ImageTypeFamily.Add("TGA");
  27. this.ImageTypeFamily.Add("BMP");
  28. this.ImageTypeFamily.Add("JPEG-2000");
  29. }
  30. public List<string> ImageDPIFamily { set; get; } = new List<string>();
  31. private void SetImageDPIOrigin()
  32. {
  33. this.ImageDPIFamily.Add("50 dpi");
  34. this.ImageDPIFamily.Add("72 dpi");
  35. this.ImageDPIFamily.Add("96 dpi");
  36. this.ImageDPIFamily.Add("150 dpi");
  37. this.ImageDPIFamily.Add("300 dpi");
  38. this.ImageDPIFamily.Add("600 dpi");
  39. }
  40. #endregion
  41. public HomePageConverterImgViewModel()
  42. {
  43. SetImageTypeOrigin();
  44. SetImageDPIOrigin();
  45. }
  46. public void UpdateImageDpi(int index) {
  47. switch (index)
  48. {
  49. case 0:
  50. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageDpi =50;
  51. break;
  52. case 1:
  53. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageDpi = 72;
  54. break;
  55. case 2:
  56. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageDpi = 96;
  57. break;
  58. case 3:
  59. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageDpi = 150;
  60. break;
  61. case 4:
  62. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageDpi = 300;
  63. break;
  64. case 5:
  65. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageDpi = 600;
  66. break;
  67. default:
  68. break;
  69. }
  70. }
  71. public void UpdateImageType(int index)
  72. {
  73. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageType = ImgType.PNG;
  74. switch (index)
  75. {
  76. //case结果是同样的情况下,case可堆叠在一起,表示处理方式一样
  77. case 0:
  78. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".jpeg";
  79. break;
  80. case 7:
  81. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".jp2";
  82. break;
  83. case 3:
  84. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".gif";
  85. break;
  86. case 4:
  87. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".tiff";
  88. break;
  89. case 5:
  90. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".tga";
  91. break;
  92. case 6:
  93. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".bmp";
  94. break;
  95. case 2:
  96. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".png";
  97. break;
  98. case 1:
  99. this.homePageConverterDialogViewModel.ConverterImgModel.imageType = ".jpg";
  100. this.homePageConverterDialogViewModel.ConverterImgModel.Options.ImageType = ImgType.JPEG;
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. #region 构架行为
  107. public void OnNavigatedTo(NavigationContext navigationContext)
  108. {
  109. var homePageConverterVM = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as HomePageConverterDialogViewModel;
  110. if (homePageConverterVM != null)
  111. {
  112. homePageConverterDialogViewModel = homePageConverterVM;
  113. UpdateImageDpi(0);
  114. UpdateImageType(0);
  115. }
  116. }
  117. public bool IsNavigationTarget(NavigationContext navigationContext)
  118. {
  119. return true;
  120. }
  121. public void OnNavigatedFrom(NavigationContext navigationContext)
  122. {
  123. }
  124. #endregion
  125. }
  126. }