Browse Source

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

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

+ 48
- 26
Common/system/ImageHelper.cs View File

404
         {
404
         {
405
             try
405
             try
406
             {
406
             {
407
-                //System.IO.FileStream fs = new System.IO.FileStream(filePathName, System.IO.FileMode.Create);
408
                 //在位图中呈现UI元素
407
                 //在位图中呈现UI元素
409
                 RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, PrimaryScreen.DpiX, PrimaryScreen.DpiY, PixelFormats.Pbgra32);
408
                 RenderTargetBitmap bmp = new RenderTargetBitmap(width, height, PrimaryScreen.DpiX, PrimaryScreen.DpiY, PixelFormats.Pbgra32);
410
                 bmp.Render(ui);
409
                 bmp.Render(ui);
411
                 BitmapEncoder encoder = new PngBitmapEncoder();
410
                 BitmapEncoder encoder = new PngBitmapEncoder();
412
                 encoder.Frames.Add(BitmapFrame.Create(bmp));
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
                     try
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 View File

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

2851
                     #region 设置录制大小
2851
                     #region 设置录制大小
2852
                     //gridActWidth = (int)GridMain.ActualWidth==0?1276: (int)GridMain.ActualWidth;
2852
                     //gridActWidth = (int)GridMain.ActualWidth==0?1276: (int)GridMain.ActualWidth;
2853
                     //gridActHeight = (int)GridMain.ActualHeight==0?898: (int)GridMain.ActualHeight;
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
                     #endregion
2858
                     #endregion
2857
 
2859
 
2858
                     #region 录像倒计时
2860
                     #region 录像倒计时
3012
                     {
3014
                     {
3013
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
3015
                         string FilePathName = ImgPath + RsImgName.Count + ".png";
3014
                         RsImgName.Add(FilePathName);
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
                         //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
3032
                         //ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)(ActualWidth * (PrimaryScreen.DpiX / 96f)), (int)(ActualHeight * (PrimaryScreen.DpiY / 96f)), 1281, 1026);
3026
                         SRTime = SRTime.AddMilliseconds(200);
3033
                         SRTime = SRTime.AddMilliseconds(200);
3027
                         if (txbTime.Visibility == Visibility.Hidden)
3034
                         if (txbTime.Visibility == Visibility.Hidden)

Loading…
Cancel
Save