Просмотр исходного кода

Merge remote-tracking branch 'origin/zxy' into zyy

tags/录制修改前
耀 4 лет назад
Родитель
Сommit
025ff51e33

+ 44
- 0
XHWK.Model/ViewModel.cs Просмотреть файл

@@ -0,0 +1,44 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.ComponentModel;
4
+using System.Linq;
5
+using System.Text;
6
+using System.Threading.Tasks;
7
+using System.Windows.Ink;
8
+
9
+namespace XHWK.Model
10
+{
11
+    public class ViewModel : INotifyPropertyChanged
12
+    {
13
+        public event PropertyChangedEventHandler PropertyChanged;
14
+
15
+        protected virtual void OnPropertyChanged(string propertyName = null)
16
+        {
17
+            if (PropertyChanged != null)
18
+                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
19
+        }
20
+
21
+        private string meaInfo;
22
+        public string MeaInfo
23
+        {
24
+            get => meaInfo;
25
+            set
26
+            {
27
+                meaInfo = value;
28
+                OnPropertyChanged("MeaInfo");
29
+            }
30
+        }
31
+
32
+        private StrokeCollection inkStrokes;
33
+        public StrokeCollection InkStrokes
34
+        {
35
+            get { return inkStrokes; }
36
+            set
37
+            {
38
+                inkStrokes = value;
39
+                OnPropertyChanged("InkStrokes");
40
+            }
41
+        }
42
+    }
43
+
44
+}

+ 12
- 0
XHWK.Model/XHWK.Model.csproj Просмотреть файл

@@ -31,8 +31,16 @@
31 31
     <WarningLevel>4</WarningLevel>
32 32
   </PropertyGroup>
33 33
   <ItemGroup>
34
+    <Reference Include="Ink, Version=0.5.0.0, Culture=neutral, processorArchitecture=MSIL">
35
+      <HintPath>..\packages\Ink.0.5.0\lib\net451\Ink.dll</HintPath>
36
+    </Reference>
37
+    <Reference Include="NStandard, Version=0.4.15.0, Culture=neutral, processorArchitecture=MSIL">
38
+      <HintPath>..\packages\NStandard.0.4.15\lib\net451\NStandard.dll</HintPath>
39
+    </Reference>
40
+    <Reference Include="PresentationCore" />
34 41
     <Reference Include="System" />
35 42
     <Reference Include="System.Core" />
43
+    <Reference Include="System.Web" />
36 44
     <Reference Include="System.Xml.Linq" />
37 45
     <Reference Include="System.Data.DataSetExtensions" />
38 46
     <Reference Include="Microsoft.CSharp" />
@@ -49,6 +57,10 @@
49 57
     <Compile Include="Model_WKData.cs" />
50 58
     <Compile Include="NotifyModel.cs" />
51 59
     <Compile Include="Properties\AssemblyInfo.cs" />
60
+    <Compile Include="ViewModel.cs" />
61
+  </ItemGroup>
62
+  <ItemGroup>
63
+    <None Include="packages.config" />
52 64
   </ItemGroup>
53 65
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
54 66
 </Project>

+ 5
- 0
XHWK.Model/packages.config Просмотреть файл

@@ -0,0 +1,5 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<packages>
3
+  <package id="Ink" version="0.5.0" targetFramework="net452" />
4
+  <package id="NStandard" version="0.4.15" targetFramework="net452" />
5
+</packages>

Двоичные данные
XHWK.WKTool/Images/Toobar12.png Просмотреть файл


Двоичные данные
XHWK.WKTool/Images/Toobar13.png Просмотреть файл


+ 1
- 1
XHWK.WKTool/PracticeWindow.xaml Просмотреть файл

@@ -14,6 +14,6 @@
14 14
     WindowStyle="None">
15 15
     <Grid>
16 16
         <Image x:Name="imgCanvas"/>
17
-        <InkCanvas Grid.Row="0" x:Name="blackboard_canvas" Background="Transparent" Visibility="Visible" Grid.ColumnSpan="2" />
17
+        <InkCanvas Grid.Row="0" x:Name="blackboard_canvas" Background="Transparent" Visibility="Visible" Grid.ColumnSpan="2" MouseDown="blackboard_canvas_MouseDown" MouseMove="blackboard_canvas_MouseMove" Width="{Binding ElementName=imgMeasure, Path=ActualWidth}" Height="{Binding ElementName=imgMeasure, Path=ActualHeight}" EditingMode="None" Strokes="{Binding InkStrokes, Mode=TwoWay}" PreviewMouseLeftButtonUp="blackboard_canvas_PreviewMouseLeftButtonUp" />
18 18
     </Grid>
19 19
 </Window>

+ 178
- 8
XHWK.WKTool/PracticeWindow.xaml.cs Просмотреть файл

@@ -13,6 +13,7 @@ using System.Windows.Input;
13 13
 using System.Windows.Media;
14 14
 using System.Windows.Media.Imaging;
15 15
 using System.Windows.Shapes;
16
+using XHWK.Model;
16 17
 
17 18
 namespace XHWK.WKTool
18 19
 {
@@ -23,12 +24,19 @@ namespace XHWK.WKTool
23 24
     {
24 25
         //声明一个 DrawingAttributes 类型的变量  
25 26
         DrawingAttributes drawingAttributes;
27
+
28
+        private ViewModel viewModel;
29
+        /// <summary>
30
+        /// 0 画笔 1 矩形 2 圆形 
31
+        /// </summary>
32
+        private int flg = 0;
26 33
         public PracticeWindow()
27 34
         {
28 35
             InitializeComponent();
29 36
         }
30 37
         public void Initialize(string _imgPath)
31 38
         {
39
+            flg = 0;
32 40
             blackboard_canvas.Strokes.Clear();
33 41
             blackboard_canvas.UseCustomCursor = true;
34 42
             //blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
@@ -36,16 +44,50 @@ namespace XHWK.WKTool
36 44
             {
37 45
                 imgCanvas.Source = new BitmapImage(new Uri(_imgPath));
38 46
             }
39
-            //创建 DrawingAttributes 类的一个实例  
40
-            drawingAttributes = new DrawingAttributes();
41
-            //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用  
42
-            //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型  
47
+
48
+
49
+            drawingAttributes = new DrawingAttributes
50
+            {
51
+                Color = Colors.Red,
52
+                Width = 2,
53
+                Height = 2,
54
+                StylusTip = StylusTip.Rectangle,
55
+                //FitToCurve = true,
56
+                IsHighlighter = false,
57
+                IgnorePressure = true,
58
+
59
+            };
43 60
             blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
44
-            Pen();
45
-            blackboard_canvas.Cursor = Cursors.Pen;
46
-            //Cursor cus = new Cursor(@"G:\Icon.ico");
61
+
62
+
63
+
64
+
65
+            ////创建 DrawingAttributes 类的一个实例  
66
+            //drawingAttributes = new DrawingAttributes();
67
+
68
+            //drawingAttributes.StylusTip = StylusTip.Rectangle;
69
+            //drawingAttributes.IsHighlighter = false;
70
+            //drawingAttributes.IgnorePressure = true;
71
+
72
+
73
+
74
+            ////将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用  
75
+            ////InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型  
76
+            //blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
77
+            //Pen();
78
+            //blackboard_canvas.Cursor = Cursors.Pen;
79
+
80
+
81
+            //Cursor cus = new Cursor(@"G:\Icon.cur");
47 82
             
48 83
             //blackboard_canvas.Cursor = cus;
84
+
85
+            viewModel = new ViewModel
86
+            {
87
+                InkStrokes = new StrokeCollection(),
88
+            };
89
+
90
+            DataContext = viewModel;
49 91
         }
50 92
 
51 93
 
@@ -57,6 +99,7 @@ namespace XHWK.WKTool
57 99
         /// <param name="e"></param>
58 100
         public void White()
59 101
         {
102
+            flg = 0;
60 103
             drawingAttributes.Color = Colors.White;
61 104
         }
62 105
         /// <summary>
@@ -66,7 +109,7 @@ namespace XHWK.WKTool
66 109
         /// <param name="e"></param>
67 110
         public void Red()
68 111
         {
69
-
112
+            flg = 0;
70 113
             //设置 DrawingAttributes 的 Color 属性设置颜色  
71 114
             drawingAttributes.Color = Colors.Red;
72 115
         }
@@ -77,6 +120,7 @@ namespace XHWK.WKTool
77 120
         /// <param name="e"></param>
78 121
         public void Gray()
79 122
         {
123
+            flg = 0;
80 124
             drawingAttributes.Color = Colors.Gray;
81 125
         }
82 126
         /// <summary>
@@ -86,6 +130,7 @@ namespace XHWK.WKTool
86 130
         /// <param name="e"></param>
87 131
         public void CyanBlue()
88 132
         {
133
+            flg = 0;
89 134
             drawingAttributes.Color = Colors.LimeGreen;
90 135
         }
91 136
         /// <summary>
@@ -95,6 +140,7 @@ namespace XHWK.WKTool
95 140
         /// <param name="e"></param>
96 141
         public void Yellow()
97 142
         {
143
+            flg = 0;
98 144
             drawingAttributes.Color = Colors.Gold;
99 145
         }
100 146
         /// <summary>
@@ -104,6 +150,7 @@ namespace XHWK.WKTool
104 150
         /// <param name="e"></param>
105 151
         public void Blue()
106 152
         {
153
+            flg = 0;
107 154
             drawingAttributes.Color = Colors.DeepSkyBlue;
108 155
         }
109 156
         /// <summary>
@@ -113,6 +160,7 @@ namespace XHWK.WKTool
113 160
         /// <param name="e"></param>
114 161
         public void Fine()
115 162
         {
163
+            flg = 0;
116 164
             drawingAttributes.Width = 1;
117 165
             drawingAttributes.Height = 1;
118 166
         }
@@ -123,6 +171,7 @@ namespace XHWK.WKTool
123 171
         /// <param name="e"></param>
124 172
         public void In()
125 173
         {
174
+            flg = 0;
126 175
             drawingAttributes.Width = 3;
127 176
             drawingAttributes.Height = 3;
128 177
         }
@@ -133,23 +182,144 @@ namespace XHWK.WKTool
133 182
         /// <param name="e"></param>
134 183
         public void Crude()
135 184
         {
185
+            flg = 0;
136 186
             drawingAttributes.Width = 5;
137 187
             drawingAttributes.Height = 5;
138 188
         }
189
+        /// <summary>
190
+        /// 橡皮
191
+        /// </summary>
139 192
         public void Eraser() 
140 193
         {
194
+            flg = 0;
141 195
             //this.type = ZPenType.Erase;
142 196
             blackboard_canvas.UseCustomCursor = false;
143 197
             blackboard_canvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
144 198
             blackboard_canvas.EraserShape = new EllipseStylusShape(64, 64, 0);
145 199
         }
200
+        /// <summary>
201
+        /// 画笔
202
+        /// </summary>
146 203
         public void Pen()
147 204
         {
205
+            flg = 0;
148 206
             blackboard_canvas.EditingMode = InkCanvasEditingMode.Ink;
149 207
             blackboard_canvas.UseCustomCursor = true;
150 208
             drawingAttributes.FitToCurve = true;
151 209
             drawingAttributes.IgnorePressure = false;
210
+        
152 211
             blackboard_canvas.Cursor = Cursors.Pen;
153 212
         }
213
+        private bool IsRound = false;
214
+        StrokeCollection StrokeCollectionRound; 
215
+        /// <summary>
216
+        /// 圆
217
+        /// </summary>
218
+        public void Round()
219
+        {
220
+            flg = 2;
221
+            blackboard_canvas.EditingMode = InkCanvasEditingMode.None;
222
+        }
223
+        /// <summary>
224
+        /// 矩形
225
+        /// </summary>
226
+        public void Rectangle()
227
+        {
228
+            flg = 1;
229
+            blackboard_canvas.EditingMode = InkCanvasEditingMode.None;
230
+        }
231
+        private System.Windows.Point iniP;
232
+        private void blackboard_canvas_MouseDown(object sender, MouseButtonEventArgs e)
233
+        {
234
+            if (flg != 0)
235
+            {
236
+                if (e.LeftButton == MouseButtonState.Pressed)
237
+                {
238
+                    iniP = e.GetPosition(blackboard_canvas);
239
+                }
240
+            }
241
+        }
242
+        Stroke StrokeRound;
243
+        Stroke StrokeRectangle; 
244
+        private void blackboard_canvas_MouseMove(object sender, MouseEventArgs e)
245
+        {
246
+            if(flg!=0)
247
+            {
248
+                if (e.LeftButton == MouseButtonState.Pressed)
249
+                {
250
+                    // Draw square
251
+                    if (flg == 1)
252
+                    {
253
+                        System.Windows.Point endP = e.GetPosition(blackboard_canvas);
254
+                        List<System.Windows.Point> pointList = new List<System.Windows.Point>
255
+                    {
256
+                        new System.Windows.Point(iniP.X, iniP.Y),
257
+                        new System.Windows.Point(iniP.X, endP.Y),
258
+                        new System.Windows.Point(endP.X, endP.Y),
259
+                        new System.Windows.Point(endP.X, iniP.Y),
260
+                        new System.Windows.Point(iniP.X, iniP.Y),
261
+                    };
262
+                        //Stroke stroke1 = new Stroke(drawingAttributesRound);
263
+                        StylusPointCollection point = new StylusPointCollection(pointList);
264
+                        Stroke stroke = new Stroke(point)
265
+                        {
266
+                            DrawingAttributes = blackboard_canvas.DefaultDrawingAttributes.Clone()
267
+                        };
268
+                        if(StrokeRectangle!=null)
269
+                        {
270
+                            viewModel.InkStrokes.Remove(StrokeRectangle);
271
+                        }
272
+                        StrokeRectangle = stroke;
273
+
274
+                        viewModel.InkStrokes.Add(stroke);
275
+                    }
276
+                    // Draw Eclipse
277
+                    else if (flg == 2)
278
+                    {
279
+                        System.Windows.Point endP = e.GetPosition(blackboard_canvas);
280
+                        List<System.Windows.Point> pointList = GenerateEclipseGeometry(iniP, endP);
281
+                        StylusPointCollection point = new StylusPointCollection(pointList);
282
+                        Stroke stroke = new Stroke(point)
283
+                        {
284
+                            DrawingAttributes = blackboard_canvas.DefaultDrawingAttributes.Clone()
285
+                        };
286
+                        //viewModel.InkStrokes.Clear();
287
+                        if(StrokeRound!=null)
288
+                        {
289
+                            viewModel.InkStrokes.Remove(StrokeRound);
290
+                        }
291
+                        StrokeRound = stroke;
292
+                        viewModel.InkStrokes.Add(stroke);
293
+                    }
294
+                }
295
+            }
296
+        }
297
+        private List<System.Windows.Point> GenerateEclipseGeometry(System.Windows.Point st, System.Windows.Point ed)
298
+        {
299
+                double a = 0.5 * (ed.X - st.X);
300
+            double b = 0.5 * (ed.Y - st.Y);
301
+            List<System.Windows.Point> pointList = new List<System.Windows.Point>();
302
+            for (double r = 0; r <= 2 * Math.PI; r = r + 0.01)
303
+            {
304
+                pointList.Add(new System.Windows.Point(0.5 * (st.X + ed.X) + a * Math.Cos(r), 0.5 * (st.Y + ed.Y) + b * Math.Sin(r)));
305
+            }
306
+            return pointList;
307
+        }
308
+
309
+        private void blackboard_canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
310
+        {
311
+
312
+        }
313
+        /// <summary>
314
+        /// 鼠标松开时
315
+        /// </summary>
316
+        /// <param name="sender"></param>
317
+        /// <param name="e"></param>
318
+        private void blackboard_canvas_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
319
+        {
320
+            StrokeRound = null;
321
+            StrokeRectangle = null;
322
+        }
154 323
     }
155 324
 }
325
+

+ 4
- 4
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml Просмотреть файл

@@ -27,7 +27,7 @@
27 27
                     <Button  Cursor="Hand" x:Name="btnToolbarDown" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnToolbarDown_Click">
28 28
                         <Image Source="./Images/Toobar5.png"/>
29 29
                     </Button>
30
-                    <Button  Cursor="Hand" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0">
30
+                    <Button  Cursor="Hand" x:Name="btnEraser" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnEraser_Click">
31 31
                         <Image Source="./Images/Toobar12.png"/>
32 32
                     </Button>
33 33
                     <Button  Cursor="Hand" x:Name="btnPen" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnPen_Click">
@@ -36,16 +36,16 @@
36 36
                     <Button  Cursor="Hand" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0">
37 37
                         <Image Source="./Images/Toobar16.png"/>
38 38
                     </Button>
39
-                    <Button  Cursor="Hand" x:Name="btnEraser" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnEraser_Click">
39
+                    <Button  Cursor="Hand" x:Name="btnRectangle" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnRectangle_Click">
40 40
                         <Image Source="./Images/Toobar3.png"/>
41 41
                     </Button>
42
-                    <Button  Cursor="Hand" x:Name="btnColour" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnColour_Click">
42
+                    <Button  Cursor="Hand" x:Name="btnRound" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnRound_Click">
43 43
                         <Image Source="./Images/Toobar23.png"/>
44 44
                     </Button>
45 45
                     <Button  Cursor="Hand" x:Name="btnThickness" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnThickness_Click">
46 46
                         <Image Source="./Images/Toobar1.png"/>
47 47
                     </Button>
48
-                    <Button  Cursor="Hand" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0">
48
+                    <Button  Cursor="Hand" x:Name="btnColour" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,5,0,0" Click="BtnColour_Click">
49 49
                         <Image Source="./Images/Toobar18.png"/>
50 50
                     </Button>
51 51
                 </StackPanel>

+ 18
- 0
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs Просмотреть файл

@@ -409,5 +409,23 @@ namespace XHWK.WKTool
409 409
         {
410 410
             APP.W_PracticeWindow.Pen();
411 411
         }
412
+        /// <summary>
413
+        /// ⚪
414
+        /// </summary>
415
+        /// <param name="sender"></param>
416
+        /// <param name="e"></param>
417
+        private void BtnRound_Click(object sender, RoutedEventArgs e) 
418
+        {
419
+            APP.W_PracticeWindow.Round();
420
+        }
421
+        /// <summary>
422
+        /// 矩形
423
+        /// </summary>
424
+        /// <param name="sender"></param>
425
+        /// <param name="e"></param>
426
+        private void BtnRectangle_Click(object sender, RoutedEventArgs e)
427
+        {
428
+            APP.W_PracticeWindow.Rectangle();
429
+        }
412 430
     }
413 431
 }

+ 188
- 83
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs Просмотреть файл

@@ -42,6 +42,10 @@ namespace XHWK.WKTool
42 42
         public event ChangeTextHandler ChangeTextEvent;
43 43
         //定义委托
44 44
         public delegate void ChangeTextHandler(string text);
45
+        /// <summary>
46
+        /// 图片
47
+        /// </summary>
48
+        string [] ImgPDFPath = new string[300]; 
45 49
         #endregion
46 50
 
47 51
         #region 初始化
@@ -86,6 +90,8 @@ namespace XHWK.WKTool
86 90
             drawingAttributes.IgnorePressure = false;
87 91
             blackboard_canvas.Cursor = System.Windows.Input.Cursors.Pen;
88 92
             wfhCamera.Visibility = Visibility.Hidden;
93
+            ImgPDFPath = null;
94
+            ImgPDFPath = new string[300];
89 95
         }
90 96
         #endregion
91 97
 
@@ -505,7 +511,7 @@ namespace XHWK.WKTool
505 511
                         Thread.Sleep(400);
506 512
                         Dispatcher.Invoke(new Action(() =>
507 513
                         {
508
-                            OpenDialogPPT();
514
+                            OpenDialog();
509 515
                         }
510 516
                             ));
511 517
                     })
@@ -519,36 +525,6 @@ namespace XHWK.WKTool
519 525
             }
520 526
         }
521 527
         private void OpenDialog()
522
-        {
523
-            result = ofd.ShowDialog();
524
-            if (result == System.Windows.Forms.DialogResult.OK)
525
-            {
526
-                if (ofd.FileName != "")
527
-                {
528
-                    string filepath = ofd.FileName;
529
-                    string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
530
-                    APP.Paths = ConvertWordToImage(filepath, path, "", 0, 0, null, 0).ToArray();
531
-
532
-                    for (int i = 0; i < APP.Paths.Length; i++)
533
-                    {
534
-                        APP.pageData.pagenum += 1;
535
-                    }
536
-                    if (APP.pageData.pagenum > 1)
537
-                    {
538
-                        APP.pageData.pagenum -= 1;
539
-                    }
540
-                    if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
541
-                    {
542
-                        imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
543
-                    }
544
-                    else
545
-                    {
546
-                        imgCanvas.Source = null;
547
-                    }
548
-                }
549
-            }
550
-        }
551
-        private void OpenDialogPPT()
552 528
         {
553 529
             result = ofd.ShowDialog();
554 530
             if (result == System.Windows.Forms.DialogResult.OK)
@@ -558,68 +534,110 @@ namespace XHWK.WKTool
558 534
                     #region PPT转PDF
559 535
                     string filepath = ofd.FileName;
560 536
                     string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
561
-                    string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
562
-                    path = pathTemp + path + ".pdf";
563
-                    //PPT转PDF
564
-                    Presentation ppt = new Presentation(filepath);
565
-                    ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf); 
566
-                    #endregion
567
-
568
-
569
-                    #region PDF转图片
570
-                    // 图片绝对路径集合
571
-                    List<string> images = new List<string>();
572
-                    string directoryPath = pathTemp;
573
-                    //aspose许可证
574
-                    //Aspose.Pdf.License l = new Aspose.Pdf.License();
575
-                    //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
576
-                    //l.SetLicense(licenseName);
577
-                    //定义Jpeg转换设备
578
-                    Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
579
-                    var device = new Aspose.Pdf.Devices.JpegDevice();
580
-                    //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
581
-                    //directoryPath += quality;
582
-                    Directory.CreateDirectory(directoryPath);
583
-                    //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
584
-                    device = new Aspose.Pdf.Devices.JpegDevice(100);
585
-                    //遍历每一页转为jpg
586
-                    for (var i = 1; i <= document.Pages.Count; i++)
537
+                    string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
538
+                    if (type.Contains("typezsygppt"))
587 539
                     {
588
-                        long ii = Timestamp();
589
-                        string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
590
-                        images.Add(filePathOutPut);
591
-                        FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
592 540
                         try
593 541
                         {
594
-                            device.Process(document.Pages[i], fs);
595
-                            fs.Close();
542
+                            string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
543
+                            path = pathTemp + path + ".pdf";
544
+                            //PPT转PDF
545
+                            Presentation ppt = new Presentation(filepath);
546
+                            ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
547
+                            #endregion
548
+
549
+
550
+                            #region PDF转图片
551
+                            // 图片绝对路径集合
552
+                            List<string> images = new List<string>();
553
+                            string directoryPath = pathTemp;
554
+                            //aspose许可证
555
+                            //Aspose.Pdf.License l = new Aspose.Pdf.License();
556
+                            //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
557
+                            //l.SetLicense(licenseName);
558
+                            //定义Jpeg转换设备
559
+                            Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
560
+                            var device = new Aspose.Pdf.Devices.JpegDevice();
561
+                            //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
562
+                            //directoryPath += quality;
563
+                            Directory.CreateDirectory(directoryPath);
564
+                            //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
565
+                            device = new Aspose.Pdf.Devices.JpegDevice(100);
566
+                            //遍历每一页转为jpg
567
+                            for (var i = 1; i <= document.Pages.Count; i++)
568
+                            {
569
+                                long ii = Timestamp();
570
+                                string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
571
+                                images.Add(filePathOutPut);
572
+                                FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
573
+                                try
574
+                                {
575
+                                    device.Process(document.Pages[i], fs);
576
+                                    fs.Close();
577
+                                }
578
+                                catch (Exception ex)
579
+                                {
580
+                                    fs.Close();
581
+                                    File.Delete(filePathOutPut);
582
+                                }
583
+                            }
584
+                            #endregion
585
+
586
+                            APP.Paths = images.ToArray();
587
+                            ImgPDFPath = images.ToArray();
588
+                            for (int i = 0; i < APP.Paths.Length; i++)
589
+                            {
590
+                                APP.pageData.pagenum += 1;
591
+                            }
592
+                            if (APP.pageData.pagenum > 1)
593
+                            {
594
+                                APP.pageData.pagenum -= 1;
595
+                            }
596
+                            if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
597
+                            {
598
+                                imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
599
+                            }
600
+                            else
601
+                            {
602
+                                imgCanvas.Source = null;
603
+                            }
596 604
                         }
597 605
                         catch (Exception ex)
598 606
                         {
599
-                            fs.Close();
600
-                            File.Delete(filePathOutPut);
607
+                            LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
601 608
                         }
602
-                    } 
603
-                    #endregion
604
-
605
-                    APP.Paths = images.ToArray(); 
606
-
607
-                    for (int i = 0; i < APP.Paths.Length; i++)
608
-                    {
609
-                        APP.pageData.pagenum += 1;
610
-                    }
611
-                    if (APP.pageData.pagenum > 1)
612
-                    {
613
-                        APP.pageData.pagenum -= 1;
614
-                    }
615
-                    if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
616
-                    {
617
-                        imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
618 609
                     }
619 610
                     else
620 611
                     {
621
-                        imgCanvas.Source = null;
612
+                        try
613
+                        {
614
+                            string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
615
+                            APP.Paths = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
616
+
617
+                            for (int i = 0; i < APP.Paths.Length; i++)
618
+                            {
619
+                                APP.pageData.pagenum += 1;
620
+                            }
621
+                            if (APP.pageData.pagenum > 1)
622
+                            {
623
+                                APP.pageData.pagenum -= 1;
624
+                            }
625
+                            if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
626
+                            {
627
+                                imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
628
+                            }
629
+                            else
630
+                            {
631
+                                imgCanvas.Source = null;
632
+                            }
633
+                        }
634
+                        catch (Exception ex)
635
+                        {
636
+                            LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
637
+                        }
622 638
                     }
639
+
640
+              
623 641
                 }
624 642
             }
625 643
         }
@@ -923,6 +941,63 @@ namespace XHWK.WKTool
923 941
         /// <param name="e"></param>
924 942
         private void BtnPrint_Click(object sender, RoutedEventArgs e)
925 943
         {
944
+            if (APP.IsLoginType == false)
945
+            {
946
+                Login();
947
+                return;
948
+            }
949
+
950
+            //for(int i=0;i< APP.pageData.pagenum; i++)
951
+            //{
952
+
953
+            //}
954
+
955
+
956
+
957
+            ////string[] files = { @"C:\101\1.jpg", @"C:\101\2.jpg" };
958
+            iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
959
+            try
960
+            {
961
+                //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
962
+                //设置纸张横向
963
+                document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
964
+
965
+
966
+                iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
967
+                document.Open();
968
+                iTextSharp.text.Image image;
969
+                for (int i = 0; i < 10/*ImgPDFPath.Length*/; i++)
970
+                {
971
+                    if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
972
+
973
+
974
+                    image = iTextSharp.text.Image.GetInstance(ImgPDFPath[i]);
975
+
976
+
977
+                    if (image.Height > iTextSharp.text.PageSize.A4.Height - 25)
978
+                    {
979
+                        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
980
+                    }
981
+                    else if (image.Width > iTextSharp.text.PageSize.A4.Width - 25)
982
+                    {
983
+                        image.ScaleToFit(iTextSharp.text.PageSize.A4.Width - 25, iTextSharp.text.PageSize.A4.Height - 25);
984
+                    }
985
+                    image.Alignment = iTextSharp.text.Image.ALIGN_MIDDLE;
986
+                    document.NewPage();
987
+                    document.Add(image);
988
+                    //iTextSharp.text.Chunk c1 = new iTextSharp.text.Chunk("Hello World");
989
+                    //iTextSharp.text.Phrase p1 = new iTextSharp.text.Phrase();
990
+                    //p1.Leading = 150;      //行间距
991
+                    //document.Add(p1);
992
+                }
993
+                Console.WriteLine("转换成功!");
994
+            }
995
+            catch (Exception ex)
996
+            {
997
+                Console.WriteLine("转换失败,原因:" + ex.Message);
998
+            }
999
+            document.Close();
1000
+            ////Console.ReadKey();
926 1001
 
927 1002
         }
928 1003
         /// <summary>
@@ -947,6 +1022,21 @@ namespace XHWK.WKTool
947 1022
         {
948 1023
             if (APP.pageData.currpage > 1)
949 1024
             {
1025
+                try
1026
+                {
1027
+                    Dispatcher.Invoke(() =>
1028
+                    {
1029
+                        string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
1030
+                        FileToolsCommon.CreateDirectory(filePath);
1031
+                        string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
1032
+                        ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
1033
+                        ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
1034
+                    });
1035
+                }
1036
+                catch (Exception ex)
1037
+                {
1038
+                    LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
1039
+                }
950 1040
                 APP.pageData.currpage -= 1;
951 1041
                 myblackboard.changepage(APP.pageData.currpage - 1);
952 1042
                 if (APP.Paths.Length > 0)
@@ -976,11 +1066,26 @@ namespace XHWK.WKTool
976 1066
         {
977 1067
             if (APP.pageData.currpage < APP.pageData.pagenum)
978 1068
             {
1069
+                try
1070
+                {
1071
+                    Dispatcher.Invoke(() =>
1072
+                    {
1073
+                        string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
1074
+                        FileToolsCommon.CreateDirectory(filePath);
1075
+                        string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
1076
+                        ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
1077
+                        ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
1078
+                    });
1079
+                }
1080
+                catch (Exception ex)
1081
+                {
1082
+                    LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
1083
+                }
979 1084
                 APP.pageData.currpage += 1;
980 1085
                 myblackboard.changepage(APP.pageData.currpage - 1);
981 1086
                 if (APP.Paths.Length > 0)
982 1087
                 {
983
-
1088
+                  
984 1089
                     if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
985 1090
                     {
986 1091
                         imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));

+ 3
- 0
XHWK.WKTool/XHWK.WKTool.csproj Просмотреть файл

@@ -62,6 +62,9 @@
62 62
     <Reference Include="Aspose.Words">
63 63
       <HintPath>..\dl\Aspose.Words.dll</HintPath>
64 64
     </Reference>
65
+    <Reference Include="itextsharp, Version=5.5.13.1, Culture=neutral, PublicKeyToken=8354ae6d2174ddca, processorArchitecture=MSIL">
66
+      <HintPath>..\packages\iTextSharp.5.5.13.1\lib\itextsharp.dll</HintPath>
67
+    </Reference>
65 68
     <Reference Include="log4net">
66 69
       <HintPath>..\Common\dlls\log4net.dll</HintPath>
67 70
     </Reference>

+ 1
- 0
XHWK.WKTool/packages.config Просмотреть файл

@@ -7,5 +7,6 @@
7 7
   <package id="AForge.Video" version="2.2.5" targetFramework="net452" />
8 8
   <package id="AForge.Video.DirectShow" version="2.2.5" targetFramework="net452" />
9 9
   <package id="Aspose.PDF" version="19.1.0" targetFramework="net452" />
10
+  <package id="iTextSharp" version="5.5.13.1" targetFramework="net452" />
10 11
   <package id="WpfAnimatedGif" version="2.0.0" targetFramework="net452" />
11 12
 </packages>

Загрузка…
Отмена
Сохранить