瀏覽代碼

画板转PDF 工具栏 圆形 矩形

tags/录制修改前
zhangxueyang 4 年之前
父節點
當前提交
c43de58d7b

+ 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>

+ 179
- 9
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.cur");
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
-            blackboard_canvas.Cursor = cus;
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 查看文件

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

+ 131
- 100
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs 查看文件

@@ -510,7 +510,7 @@ namespace XHWK.WKTool
510 510
                         Thread.Sleep(400);
511 511
                         Dispatcher.Invoke(new Action(() =>
512 512
                         {
513
-                            OpenDialogPPT();
513
+                            OpenDialog();
514 514
                         }
515 515
                             ));
516 516
                     })
@@ -524,36 +524,6 @@ namespace XHWK.WKTool
524 524
             }
525 525
         }
526 526
         private void OpenDialog()
527
-        {
528
-            result = ofd.ShowDialog();
529
-            if (result == System.Windows.Forms.DialogResult.OK)
530
-            {
531
-                if (ofd.FileName != "")
532
-                {
533
-                    string filepath = ofd.FileName;
534
-                    string path = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
535
-                    APP.Paths = ConvertWordToImage(filepath, path, "", 0, 0, null, 0).ToArray();
536
-
537
-                    for (int i = 0; i < APP.Paths.Length; i++)
538
-                    {
539
-                        APP.pageData.pagenum += 1;
540
-                    }
541
-                    if (APP.pageData.pagenum > 1)
542
-                    {
543
-                        APP.pageData.pagenum -= 1;
544
-                    }
545
-                    if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
546
-                    {
547
-                        imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
548
-                    }
549
-                    else
550
-                    {
551
-                        imgCanvas.Source = null;
552
-                    }
553
-                }
554
-            }
555
-        }
556
-        private void OpenDialogPPT()
557 527
         {
558 528
             result = ofd.ShowDialog();
559 529
             if (result == System.Windows.Forms.DialogResult.OK)
@@ -563,68 +533,110 @@ namespace XHWK.WKTool
563 533
                     #region PPT转PDF
564 534
                     string filepath = ofd.FileName;
565 535
                     string path = ofd.SafeFileName.Replace(".ppt", "").Trim();
566
-                    string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
567
-                    path = pathTemp + path + ".pdf";
568
-                    //PPT转PDF
569
-                    Presentation ppt = new Presentation(filepath);
570
-                    ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf); 
571
-                    #endregion
572
-
573
-
574
-                    #region PDF转图片
575
-                    // 图片绝对路径集合
576
-                    List<string> images = new List<string>();
577
-                    string directoryPath = pathTemp;
578
-                    //aspose许可证
579
-                    //Aspose.Pdf.License l = new Aspose.Pdf.License();
580
-                    //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
581
-                    //l.SetLicense(licenseName);
582
-                    //定义Jpeg转换设备
583
-                    Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
584
-                    var device = new Aspose.Pdf.Devices.JpegDevice();
585
-                    //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
586
-                    //directoryPath += quality;
587
-                    Directory.CreateDirectory(directoryPath);
588
-                    //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
589
-                    device = new Aspose.Pdf.Devices.JpegDevice(100);
590
-                    //遍历每一页转为jpg
591
-                    for (var i = 1; i <= document.Pages.Count; i++)
536
+                    string type = ofd.SafeFileName.Replace(".ppt", "typezsygppt").Trim();
537
+                    if (type.Contains("typezsygppt"))
592 538
                     {
593
-                        long ii = Timestamp();
594
-                        string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
595
-                        images.Add(filePathOutPut);
596
-                        FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
597 539
                         try
598 540
                         {
599
-                            device.Process(document.Pages[i], fs);
600
-                            fs.Close();
541
+                            string pathTemp = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
542
+                            path = pathTemp + path + ".pdf";
543
+                            //PPT转PDF
544
+                            Presentation ppt = new Presentation(filepath);
545
+                            ppt.Save(path, Aspose.Slides.Export.SaveFormat.Pdf);
546
+                            #endregion
547
+
548
+
549
+                            #region PDF转图片
550
+                            // 图片绝对路径集合
551
+                            List<string> images = new List<string>();
552
+                            string directoryPath = pathTemp;
553
+                            //aspose许可证
554
+                            //Aspose.Pdf.License l = new Aspose.Pdf.License();
555
+                            //string licenseName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Aspose.Total.Product.Family.lic");
556
+                            //l.SetLicense(licenseName);
557
+                            //定义Jpeg转换设备
558
+                            Aspose.Pdf.Document document = new Aspose.Pdf.Document(path);
559
+                            var device = new Aspose.Pdf.Devices.JpegDevice();
560
+                            //int quality = int.Parse(this.comboBox1.SelectedItem.ToString());
561
+                            //directoryPath += quality;
562
+                            Directory.CreateDirectory(directoryPath);
563
+                            //默认质量为100,设置质量的好坏与处理速度不成正比,甚至是设置的质量越低反而花的时间越长,怀疑处理过程是先生成高质量的再压缩
564
+                            device = new Aspose.Pdf.Devices.JpegDevice(100);
565
+                            //遍历每一页转为jpg
566
+                            for (var i = 1; i <= document.Pages.Count; i++)
567
+                            {
568
+                                long ii = Timestamp();
569
+                                string filePathOutPut = Path.Combine(directoryPath, string.Format("{0}{1}.jpg", ii, i));
570
+                                images.Add(filePathOutPut);
571
+                                FileStream fs = new FileStream(filePathOutPut, FileMode.OpenOrCreate);
572
+                                try
573
+                                {
574
+                                    device.Process(document.Pages[i], fs);
575
+                                    fs.Close();
576
+                                }
577
+                                catch (Exception ex)
578
+                                {
579
+                                    fs.Close();
580
+                                    File.Delete(filePathOutPut);
581
+                                }
582
+                            }
583
+                            #endregion
584
+
585
+                            APP.Paths = images.ToArray();
586
+                            ImgPDFPath = images.ToArray();
587
+                            for (int i = 0; i < APP.Paths.Length; i++)
588
+                            {
589
+                                APP.pageData.pagenum += 1;
590
+                            }
591
+                            if (APP.pageData.pagenum > 1)
592
+                            {
593
+                                APP.pageData.pagenum -= 1;
594
+                            }
595
+                            if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
596
+                            {
597
+                                imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
598
+                            }
599
+                            else
600
+                            {
601
+                                imgCanvas.Source = null;
602
+                            }
601 603
                         }
602 604
                         catch (Exception ex)
603 605
                         {
604
-                            fs.Close();
605
-                            File.Delete(filePathOutPut);
606
+                            LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PPT)" + ex.Message, ex);
606 607
                         }
607
-                    } 
608
-                    #endregion
609
-
610
-                    APP.Paths = images.ToArray();
611
-                    ImgPDFPath= images.ToArray();
612
-                    for (int i = 0; i < APP.Paths.Length; i++)
613
-                    {
614
-                        APP.pageData.pagenum += 1;
615
-                    }
616
-                    if (APP.pageData.pagenum > 1)
617
-                    {
618
-                        APP.pageData.pagenum -= 1;
619
-                    }
620
-                    if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
621
-                    {
622
-                        imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
623 608
                     }
624 609
                     else
625 610
                     {
626
-                        imgCanvas.Source = null;
611
+                        try
612
+                        {
613
+                            string paths = AppDomain.CurrentDomain.BaseDirectory + "Temp\\";
614
+                            APP.Paths = ConvertWordToImage(filepath, paths, "", 0, 0, null, 0).ToArray();
615
+
616
+                            for (int i = 0; i < APP.Paths.Length; i++)
617
+                            {
618
+                                APP.pageData.pagenum += 1;
619
+                            }
620
+                            if (APP.pageData.pagenum > 1)
621
+                            {
622
+                                APP.pageData.pagenum -= 1;
623
+                            }
624
+                            if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage < APP.Paths.Length)
625
+                            {
626
+                                imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage - 1]));
627
+                            }
628
+                            else
629
+                            {
630
+                                imgCanvas.Source = null;
631
+                            }
632
+                        }
633
+                        catch (Exception ex)
634
+                        {
635
+                            LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(OpenDialog PDF)" + ex.Message, ex);
636
+                        }
627 637
                     }
638
+
639
+              
628 640
                 }
629 641
             }
630 642
         }
@@ -943,10 +955,15 @@ namespace XHWK.WKTool
943 955
             iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 25, 25);
944 956
             try
945 957
             {
958
+                //iTextSharp.text.Rectangle page = new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.A4., 250f);//cs
959
+                //设置纸张横向
960
+                document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
961
+
962
+
946 963
                 iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream(@"G:\101.pdf", FileMode.Create, FileAccess.ReadWrite));
947 964
                 document.Open();
948 965
                 iTextSharp.text.Image image;
949
-                for (int i = 0; i < ImgPDFPath.Length; i++)
966
+                for (int i = 0; i < 10/*ImgPDFPath.Length*/; i++)
950 967
                 {
951 968
                     if (String.IsNullOrEmpty(ImgPDFPath[i])) break;
952 969
 
@@ -1002,6 +1019,21 @@ namespace XHWK.WKTool
1002 1019
         {
1003 1020
             if (APP.pageData.currpage > 1)
1004 1021
             {
1022
+                try
1023
+                {
1024
+                    Dispatcher.Invoke(() =>
1025
+                    {
1026
+                        string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
1027
+                        FileToolsCommon.CreateDirectory(filePath);
1028
+                        string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
1029
+                        ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
1030
+                        ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
1031
+                    });
1032
+                }
1033
+                catch (Exception ex)
1034
+                {
1035
+                    LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(last_button_Click)生成图片错误:" + ex.Message, ex);
1036
+                }
1005 1037
                 APP.pageData.currpage -= 1;
1006 1038
                 myblackboard.changepage(APP.pageData.currpage - 1);
1007 1039
                 if (APP.Paths.Length > 0)
@@ -1031,11 +1063,26 @@ namespace XHWK.WKTool
1031 1063
         {
1032 1064
             if (APP.pageData.currpage < APP.pageData.pagenum)
1033 1065
             {
1066
+                try
1067
+                {
1068
+                    Dispatcher.Invoke(() =>
1069
+                    {
1070
+                        string filePath = FileToolsCommon.GetFileAbsolutePath("/Data/" + APP.UserInfo.Username + "/pdfimagetemp/");
1071
+                        FileToolsCommon.CreateDirectory(filePath);
1072
+                        string filePathName = filePath + APP.pageData.currpage.ToString() + ".jpg";
1073
+                        ImageHelper.SaveUIToImage(GridMain, filePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
1074
+                        ImgPDFPath[APP.pageData.currpage - 1] = filePathName;
1075
+                    });
1076
+                }
1077
+                catch (Exception ex)
1078
+                {
1079
+                    LogHelper.WriteErrLog("【XHMicroLessonSystemWindow】(next_btn_Click)生成图片错误:" + ex.Message, ex);
1080
+                }
1034 1081
                 APP.pageData.currpage += 1;
1035 1082
                 myblackboard.changepage(APP.pageData.currpage - 1);
1036 1083
                 if (APP.Paths.Length > 0)
1037 1084
                 {
1038
-
1085
+                  
1039 1086
                     if (!string.IsNullOrWhiteSpace(txbCurrpage.Text) && APP.pageData.currpage <= APP.Paths.Length)
1040 1087
                     {
1041 1088
                         imgCanvas.Source = new BitmapImage(new Uri(APP.Paths[APP.pageData.currpage-1]));
@@ -1049,22 +1096,6 @@ namespace XHWK.WKTool
1049 1096
                 {
1050 1097
                     imgCanvas.Source = new BitmapImage(new Uri(APP.JPaths[APP.pageData.currpage]));
1051 1098
                 }
1052
-
1053
-
1054
-
1055
-                try
1056
-                {
1057
-                    Dispatcher.Invoke(() =>
1058
-                    {
1059
-                        string FilePathName  = AppDomain.CurrentDomain.BaseDirectory + "Temp\\" +"pdf"+ APP.pageData.currpage.ToString() + ".jpg";
1060
-                        ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
1061
-                    ImgPDFPath[APP.pageData.currpage - 1] =FilePathName;
1062
-                    });
1063
-                }
1064
-                catch (Exception ex)
1065
-                {
1066
-                    LogHelper.WriteErrLog("【录制】(Timer_Elapsed)生成图片错误:" + ex.Message, ex);
1067
-                }
1068 1099
             }
1069 1100
         }
1070 1101
         /// <summary>

Loading…
取消
儲存