Browse Source

zhao:1解决最后一个视频无法删除 2限制录制存储图片大小

tags/录制修改前
耀 4 years ago
parent
commit
1a6e8dd0a4

+ 9
- 2
Common/system/FileToolsCommon.cs View File

785
         /// <param name="filePath">文件的绝对路径</param>  
785
         /// <param name="filePath">文件的绝对路径</param>  
786
         public static void DeleteFile(string filePath)
786
         public static void DeleteFile(string filePath)
787
         {
787
         {
788
-            if (IsExistFile(filePath))
788
+            try
789
             {
789
             {
790
-                File.Delete(filePath);
790
+                if (IsExistFile(filePath))
791
+                {
792
+                    File.Delete(filePath);
793
+                }
794
+            }
795
+            catch (Exception ex)
796
+            {
797
+
791
             }
798
             }
792
         }
799
         }
793
         #endregion
800
         #endregion

+ 45
- 16
Common/system/ImageHelper.cs View File

1
 using System;
1
 using System;
2
 using System.Drawing;
2
 using System.Drawing;
3
+using System.Drawing.Drawing2D;
3
 using System.Drawing.Imaging;
4
 using System.Drawing.Imaging;
4
 using System.IO;
5
 using System.IO;
5
 using System.Text;
6
 using System.Text;
98
                     bitmap.EndInit();
99
                     bitmap.EndInit();
99
                     bitmap.Freeze();
100
                     bitmap.Freeze();
100
                 }
101
                 }
101
-                return bitmap; 
102
+                return bitmap;
102
             }
103
             }
103
             catch (Exception)
104
             catch (Exception)
104
             {
105
             {
395
         /// </summary>
396
         /// </summary>
396
         /// <param name="ui">需要截图的UI控件</param>
397
         /// <param name="ui">需要截图的UI控件</param>
397
         /// <param name="filePathName">图片保存地址 命名 1.png</param>
398
         /// <param name="filePathName">图片保存地址 命名 1.png</param>
398
-        /// <param name="width">保存宽</param>
399
-        /// <param name="height">保存高</param>
400
-        public static void SaveUIToImage(FrameworkElement ui, string filePathName, int width, int height)
399
+        /// <param name="width">窗口宽</param>
400
+        /// <param name="height">窗口高</param>
401
+        /// <param name="ImgWidth">图片高</param>
402
+        /// <param name="ImgHeight">图片高</param>
403
+        public static void SaveUIToImage(FrameworkElement ui, string filePathName, int width, int height, int ImgWidth, int ImgHeight)
401
         {
404
         {
402
             try
405
             try
403
             {
406
             {
404
-                System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
407
+                //System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
405
                 //在位图中呈现UI元素
408
                 //在位图中呈现UI元素
406
-                RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, PrimaryScreen.DpiX, PrimaryScreen.DpiY,
407
-                PixelFormats.Pbgra32);
409
+                RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, PrimaryScreen.DpiX, PrimaryScreen.DpiY, PixelFormats.Pbgra32);
408
                 bmp.Render(ui);
410
                 bmp.Render(ui);
409
                 BitmapEncoder encoder = new PngBitmapEncoder();
411
                 BitmapEncoder encoder = new PngBitmapEncoder();
410
                 encoder.Frames.Add(BitmapFrame.Create(bmp));
412
                 encoder.Frames.Add(BitmapFrame.Create(bmp));
411
-                encoder.Save(fs);
412
-                fs.Close();
413
-                new Thread(new ThreadStart(new Action(() =>
413
+                //encoder.Save(fs);
414
+                //fs.Close();
415
+                Bitmap Img = new Bitmap(ImgWidth, ImgHeight);
416
+                try
414
                 {
417
                 {
415
-                    Bitmap bitmap = CutImageWhitePart(filePathName);
416
-                    FileToolsCommon.DeleteFile(filePathName);
417
-                    bitmap.Save(filePathName);
418
-                }))).Start();
418
+                    MemoryStream memoryStream = new MemoryStream();
419
+                    encoder.Save(memoryStream);
420
+                    //System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
421
+                    Bitmap bit = new Bitmap(memoryStream);
422
+                    try
423
+                    {
424
+                        Graphics g = Graphics.FromImage(Img);
425
+                        //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
426
+                        g.DrawImage(bit, new Rectangle(0, 0, ImgWidth, ImgHeight), new Rectangle(0, 0, (int)bit.Width, (int)bit.Height), GraphicsUnit.Pixel);
427
+                        g.Dispose();
428
+                    }
429
+                    catch
430
+                    {
431
+                        Img = bit;
432
+                    }
433
+                    new Thread(new ThreadStart(new Action(() =>
434
+                    {
435
+                        //Img.Save(filePathName);
436
+                        Bitmap bitmap = CutImageWhitePart(Img);
437
+                        FileToolsCommon.DeleteFile(filePathName);
438
+                        bitmap.Save(filePathName);
439
+                        bitmap.Dispose();
440
+                        Img.Dispose();
441
+                        bit.Dispose();
442
+                    }))).Start();
443
+                }
444
+                catch (Exception ex)
445
+                {
446
+
447
+                }
419
             }
448
             }
420
             catch (Exception ex)
449
             catch (Exception ex)
421
             {
450
             {
430
         /// 裁剪图片(去掉白边)
459
         /// 裁剪图片(去掉白边)
431
         /// </summary>
460
         /// </summary>
432
         /// <param name="FilePath"></param>
461
         /// <param name="FilePath"></param>
433
-        public static Bitmap CutImageWhitePart(string FilePath)
462
+        public static Bitmap CutImageWhitePart(Bitmap bmp)
434
         {
463
         {
435
-            Bitmap bmp = new Bitmap(FilePath);
464
+            //Bitmap bmp = new Bitmap(FilePath);
436
             //上左右下
465
             //上左右下
437
             int top = 0, left = 0, right = bmp.Width, bottom = bmp.Height;
466
             int top = 0, left = 0, right = bmp.Width, bottom = bmp.Height;
438
 
467
 

+ 1
- 0
XHWK.WKTool/UControl/Uc_VideoItem.xaml.cs View File

241
                             ImgVideo.Source = null;
241
                             ImgVideo.Source = null;
242
                             GC.Collect();
242
                             GC.Collect();
243
                             FileToolsCommon.DeleteFile(ThumbnailPath);
243
                             FileToolsCommon.DeleteFile(ThumbnailPath);
244
+                            this.Visibility = Visibility.Hidden;
244
                             return;
245
                             return;
245
                         }
246
                         }
246
                         catch (Exception ex)
247
                         catch (Exception ex)

+ 1
- 1
XHWK.WKTool/XHMicroLessonSystemWindow.xaml View File

619
             </Grid>
619
             </Grid>
620
 
620
 
621
 
621
 
622
-            <Grid x:Name="GridMyVideo" Grid.Row="1" Margin="0" Background="White" Visibility="Collapsed">
622
+            <Grid x:Name="GridMyVideo" Grid.Row="1" Margin="0" Background="White" Visibility="Hidden">
623
                 <Grid.RowDefinitions>
623
                 <Grid.RowDefinitions>
624
                     <RowDefinition Height="*"/>
624
                     <RowDefinition Height="*"/>
625
                     <RowDefinition Height="50"/>
625
                     <RowDefinition Height="50"/>

+ 22
- 1
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

2353
                 BtnVideoUpPage.Visibility = Visibility.Hidden;
2353
                 BtnVideoUpPage.Visibility = Visibility.Hidden;
2354
                 lblVideoPageNum.Visibility = Visibility.Hidden;
2354
                 lblVideoPageNum.Visibility = Visibility.Hidden;
2355
                 BtnVideoDownPage.Visibility = Visibility.Hidden;
2355
                 BtnVideoDownPage.Visibility = Visibility.Hidden;
2356
+                //隐藏显示的控件
2357
+                if (VideoControlList.Count > 0)
2358
+                {
2359
+                    foreach (Uc_VideoItem item in VideoControlList)
2360
+                    {
2361
+                        if (item.Visibility != Visibility.Hidden)
2362
+                        {
2363
+                            item.Visibility = Visibility.Hidden;
2364
+                        }
2365
+                    }
2366
+                }
2356
             }
2367
             }
2357
             APP.myloading.Hide();
2368
             APP.myloading.Hide();
2358
         }
2369
         }
2975
                     {
2986
                     {
2976
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
2987
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
2977
                         RsImgName.Add(FilePathName);
2988
                         RsImgName.Add(FilePathName);
2978
-                        ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)));
2989
+                        double RsW = (int)(ActualWidth * (PrimaryScreen.DpiX / 96f));
2990
+                        double RsH = (int)(ActualHeight * (PrimaryScreen.DpiY / 96f));
2991
+                        if (RsW > 1281)
2992
+                        {
2993
+                            //double Proportion = RsH / RsW;
2994
+                            RsW = 1281;
2995
+                            //RsH = RsW * Proportion;
2996
+                            RsH = 1026;
2997
+                        }
2998
+                        ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW,(int)RsH);
2999
+                        //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
2979
                         SRTime = SRTime.AddMilliseconds(200);
3000
                         SRTime = SRTime.AddMilliseconds(200);
2980
                         if (txbTime.Visibility == Visibility.Hidden)
3001
                         if (txbTime.Visibility == Visibility.Hidden)
2981
                         {
3002
                         {

Loading…
Cancel
Save