瀏覽代碼

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

tags/录制修改前
耀 4 年之前
父節點
當前提交
1a6e8dd0a4

+ 9
- 2
Common/system/FileToolsCommon.cs 查看文件

@@ -785,9 +785,16 @@ namespace Common.system
785 785
         /// <param name="filePath">文件的绝对路径</param>  
786 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 800
         #endregion

+ 45
- 16
Common/system/ImageHelper.cs 查看文件

@@ -1,5 +1,6 @@
1 1
 using System;
2 2
 using System.Drawing;
3
+using System.Drawing.Drawing2D;
3 4
 using System.Drawing.Imaging;
4 5
 using System.IO;
5 6
 using System.Text;
@@ -98,7 +99,7 @@ namespace Common.system
98 99
                     bitmap.EndInit();
99 100
                     bitmap.Freeze();
100 101
                 }
101
-                return bitmap; 
102
+                return bitmap;
102 103
             }
103 104
             catch (Exception)
104 105
             {
@@ -395,27 +396,55 @@ namespace Common.system
395 396
         /// </summary>
396 397
         /// <param name="ui">需要截图的UI控件</param>
397 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 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 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 410
                 bmp.Render(ui);
409 411
                 BitmapEncoder encoder = new PngBitmapEncoder();
410 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 449
             catch (Exception ex)
421 450
             {
@@ -430,9 +459,9 @@ namespace Common.system
430 459
         /// 裁剪图片(去掉白边)
431 460
         /// </summary>
432 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 466
             int top = 0, left = 0, right = bmp.Width, bottom = bmp.Height;
438 467
 

+ 1
- 0
XHWK.WKTool/UControl/Uc_VideoItem.xaml.cs 查看文件

@@ -241,6 +241,7 @@ namespace XHWK.WKTool.UControl
241 241
                             ImgVideo.Source = null;
242 242
                             GC.Collect();
243 243
                             FileToolsCommon.DeleteFile(ThumbnailPath);
244
+                            this.Visibility = Visibility.Hidden;
244 245
                             return;
245 246
                         }
246 247
                         catch (Exception ex)

+ 1
- 1
XHWK.WKTool/XHMicroLessonSystemWindow.xaml 查看文件

@@ -619,7 +619,7 @@
619 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 623
                 <Grid.RowDefinitions>
624 624
                     <RowDefinition Height="*"/>
625 625
                     <RowDefinition Height="50"/>

+ 22
- 1
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs 查看文件

@@ -2353,6 +2353,17 @@ namespace XHWK.WKTool
2353 2353
                 BtnVideoUpPage.Visibility = Visibility.Hidden;
2354 2354
                 lblVideoPageNum.Visibility = Visibility.Hidden;
2355 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 2368
             APP.myloading.Hide();
2358 2369
         }
@@ -2975,7 +2986,17 @@ namespace XHWK.WKTool
2975 2986
                     {
2976 2987
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
2977 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 3000
                         SRTime = SRTime.AddMilliseconds(200);
2980 3001
                         if (txbTime.Visibility == Visibility.Hidden)
2981 3002
                         {

Loading…
取消
儲存