浏览代码

zhao:优化录制,固定录制视频大小

tags/录制修改前
耀 4 年前
父节点
当前提交
c8627932ec
共有 3 个文件被更改,包括 69 次插入38 次删除
  1. 48
    26
      Common/system/ImageHelper.cs
  2. 2
    0
      XHWK.WKTool/XHMicroLessonSystemWindow.xaml
  3. 19
    12
      XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs

+ 48
- 26
Common/system/ImageHelper.cs 查看文件

@@ -404,45 +404,67 @@ namespace Common.system
404 404
         {
405 405
             try
406 406
             {
407
-                //System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
408 407
                 //在位图中呈现UI元素
409 408
                 RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, PrimaryScreen.DpiX, PrimaryScreen.DpiY, PixelFormats.Pbgra32);
410 409
                 bmp.Render(ui);
411 410
                 BitmapEncoder encoder = new PngBitmapEncoder();
412 411
                 encoder.Frames.Add(BitmapFrame.Create(bmp));
413
-                //encoder.Save(fs);
414
-                //fs.Close();
415
-                Bitmap Img = new Bitmap(ImgWidth, ImgHeight);
416
-                try
412
+                if (ImgWidth > 0)
417 413
                 {
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);
414
+                    Bitmap Img = new Bitmap(ImgWidth, ImgHeight);
422 415
                     try
423 416
                     {
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();
417
+                        MemoryStream memoryStream = new MemoryStream();
418
+                        encoder.Save(memoryStream);
419
+                        //System.Drawing.Image img = System.Drawing.Image.FromStream(memoryStream);
420
+                        Bitmap bit = new Bitmap(memoryStream);
421
+                        try
422
+                        {
423
+                            Graphics g = Graphics.FromImage(Img);
424
+                            //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
425
+                            g.DrawImage(bit, new Rectangle(0, 0, ImgWidth, ImgHeight), new Rectangle(0, 0, (int)bit.Width, (int)bit.Height), GraphicsUnit.Pixel);
426
+                            g.Dispose();
427
+                        }
428
+                        catch
429
+                        {
430
+                            Img = bit;
431
+                        }
432
+                        new Thread(new ThreadStart(new Action(() =>
433
+                        {
434
+                            Img.Save(filePathName);
435
+                            //Bitmap bitmap = CutImageWhitePart(Img);
436
+                            //FileToolsCommon.DeleteFile(filePathName);
437
+                            //bitmap.Save(filePathName);
438
+                            //bitmap.Dispose();
439
+                            Img.Dispose();
440
+                            bit.Dispose();
441
+                        }))).Start();
428 442
                     }
429
-                    catch
443
+                    catch (Exception ex)
430 444
                     {
431
-                        Img = bit;
445
+
432 446
                     }
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 447
                 }
444
-                catch (Exception ex)
448
+                else
445 449
                 {
450
+                    System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
451
+                    encoder.Save(fs);
452
+                    fs.Close();
453
+
454
+                    //MemoryStream memoryStream = new MemoryStream();
455
+                    //encoder.Save(memoryStream);
456
+                    //Bitmap bit = new Bitmap(memoryStream);
457
+                    //bit.Save(filePathName);
458
+                    //bit.Dispose();
459
+
460
+                    //using (FileStream tFileStream = new FileStream(filePathName,FileMode.Create, FileAccess.Write))
461
+                    //{
462
+                    //    PngBitmapEncoder tPngBitmapEncoder = new PngBitmapEncoder();
463
+                    //    tPngBitmapEncoder.Interlace = PngInterlaceOption.On;
464
+                    //    tPngBitmapEncoder.Frames.Add(BitmapFrame.Create(bmp));
465
+                    //    tPngBitmapEncoder.Save(tFileStream);
466
+                    //    tFileStream.Close();
467
+                    //}
446 468
 
447 469
                 }
448 470
             }

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

@@ -296,6 +296,7 @@
296 296
                 </StackPanel>
297 297
             </Grid>
298 298
             <!--主内容-->
299
+            <Border  Grid.Row="1">
299 300
             <Grid Grid.Row="1" x:Name="GridMain" Visibility="Visible" MouseLeftButtonDown="Window_MouseLeftButtonDown_1">
300 301
                 <ScrollViewer x:Name="scroMain" VerticalScrollBarVisibility="Visible" MouseLeftButtonDown="Window_MouseLeftButtonDown_1">
301 302
                     <Grid x:Name="gridM"  Margin="0,0,0,0" Background="#FFFFFF" Visibility="Visible" Height="1780" MouseLeftButtonDown="Window_MouseLeftButtonDown_1">
@@ -355,6 +356,7 @@
355 356
                 <Label Content="" Grid.Column="1" Height="2" Width="2" Background="#FF0F0F0F" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,0,16,0"/>
356 357
                 <!--<TextBlock x:Name="txbTime" Text="123456" FontSize="20" Foreground="#000000" Margin="0,0,0,10" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>-->
357 358
             </Grid>
359
+            </Border>
358 360
             <!--页码-->
359 361
             <Grid Grid.Row="1" x:Name="gridPage" Visibility="Collapsed" MouseLeftButtonDown="Window_MouseLeftButtonDown_1">
360 362
                 <StackPanel Grid.Row="0" Orientation="Horizontal" Background="Transparent" Width="180" HorizontalAlignment="Center" Height="30" Margin="0,0,0,0" Grid.Column="1" VerticalAlignment="Bottom">

+ 19
- 12
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs 查看文件

@@ -2851,8 +2851,10 @@ namespace XHWK.WKTool
2851 2851
                     #region 设置录制大小
2852 2852
                     //gridActWidth = (int)GridMain.ActualWidth==0?1276: (int)GridMain.ActualWidth;
2853 2853
                     //gridActHeight = (int)GridMain.ActualHeight==0?898: (int)GridMain.ActualHeight;
2854
-                    gridActWidth = 1276;
2855
-                    gridActHeight = 898;
2854
+                    gridActWidth = (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f));
2855
+                    gridActHeight = (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f));
2856
+                    gridActWidth = gridActWidth % 2 > 0 ? gridActWidth - 1 : gridActWidth;
2857
+                    gridActHeight = gridActHeight % 2 > 0 ? gridActHeight - 1 : gridActHeight;
2856 2858
                     #endregion
2857 2859
 
2858 2860
                     #region 录像倒计时
@@ -3012,16 +3014,21 @@ namespace XHWK.WKTool
3012 3014
                     {
3013 3015
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
3014 3016
                         RsImgName.Add(FilePathName);
3015
-                        double RsW = (int)(ActualWidth * (PrimaryScreen.DpiX / 96f));
3016
-                        double RsH = (int)(ActualHeight * (PrimaryScreen.DpiY / 96f));
3017
-                        if (RsW > 1281)
3018
-                        {
3019
-                            //double Proportion = RsH / RsW;
3020
-                            RsW = 1281;
3021
-                            //RsH = RsW * Proportion;
3022
-                            RsH = 1026;
3023
-                        }
3024
-                        ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW,(int)RsH);
3017
+                        #region 设置大小
3018
+                        //double RsW = (int)(ActualWidth * (PrimaryScreen.DpiX / 96f));
3019
+                        //double RsH = (int)(ActualHeight * (PrimaryScreen.DpiY / 96f));
3020
+                        //if (RsW > 1281)
3021
+                        //{
3022
+                        //    //double Proportion = RsH / RsW;
3023
+                        //    RsW = 1281;
3024
+                        //    //RsH = RsW * Proportion;
3025
+                        //    RsH = 1026;
3026
+                        //}
3027
+                        #endregion         
3028
+                        //保存图片
3029
+                        ImageHelper.SaveUIToImage(GridMain, FilePathName, gridActWidth, gridActHeight, 0, 0);
3030
+                        //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(GridMain.ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(GridMain.ActualHeight * (PrimaryScreen.DpiY / 96f)), 0, 0);
3031
+                        //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), (int)RsW, (int)RsH);
3025 3032
                         //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
3026 3033
                         SRTime = SRTime.AddMilliseconds(200);
3027 3034
                         if (txbTime.Visibility == Visibility.Hidden)

正在加载...
取消
保存