/// <summary> /// 胶片截屏 /// </summary> /// <param name="viewerControlSize"></param> /// <param name="filmingPagePageControl"></param> /// <param name="filmingViewerControl"></param> /// <param name="ifSaveImageAsGreyScale"></param> /// <returns></returns> private WriteableBitmap RenderViewerControlToBitmap(Size viewerControlSize, FilmPageControl filmingPagePageControl, MedViewerControl filmingViewerControl, bool ifSaveImageAsGreyScale = true) { try { Logger.LogFuncUp(); MedViewerScreenSaver viewerScreenSaver = new MedViewerScreenSaver(filmingViewerControl); Logger.LogFuncUp("Start RenderViewerControlToBitmap"); BitmapSource viewerControlBitmap = viewerScreenSaver.RenderViewerControlToBitmap(viewerControlSize, Printers.Instance.IfPrintSplitterLine, true); Logger.LogFuncDown("End RenderViewerControlToBitmap"); WriteableBitmap writableViewerControlBitmap = ifSaveImageAsGreyScale ? new WriteableBitmap( new FormatConvertedBitmap( viewerControlBitmap, PixelFormats.Gray8, null, 0)) : new WriteableBitmap( new FormatConvertedBitmap(viewerControlBitmap, PixelFormats.Rgb24, null, 0)); Logger.LogFuncDown(); return(writableViewerControlBitmap); } catch (Exception ex) { Logger.LogFuncException(ex.Message + ex.StackTrace); throw; } }
public RenderWindow() { InitializeComponent(); this._filmPageControl = new FilmPageControl(); MainGrid.Children.Add(_filmPageControl); this.SetRenderPosition(new Size(FilmingUtility.DisplayedFilmPageWidth, FilmingUtility.DisplayedFilmPageHeight)); }
public WriteableBitmap RenderToBitmap(Size filmSize, string pageTitlePosition, FilmPageControl filmingPagePageControl, MedViewerControl medViewerControl, Grid filmingPageBarGrid, Grid filmingPageBarGridSimple, bool ifSaveImageAsGreyScale = true, bool ifPageNo = true) { try { Logger.LogFuncUp(); double headerScale = FilmingUtility.HEADER_PERCENTAGE_OF_FILMPAGE; bool ifHeaderSimple = (pageTitlePosition == "0" && ifPageNo); if (ifHeaderSimple) { filmPageBarGrid.Visibility = Visibility.Collapsed; Grid.SetRow(filmPageBarGrid, 1); Grid.SetRow(filmingPageBarGridSimple, 0); headerScale = 0.03; } else { filmPageBarGrid.Visibility = Visibility.Visible; Grid.SetRow(filmPageBarGrid, 0); Grid.SetRow(filmingPageBarGridSimple, 1); } //计算viewcontrol尺寸,title尺寸的比例 double scale = filmSize.Height > filmSize.Width ? headerScale : headerScale * filmSize.Width / filmSize.Height; //生成viewcontrol的Size并截屏 var viewerControlSize = pageTitlePosition != "0" ? new Size(filmSize.Width, filmSize.Height * (1 - scale)) : (ifPageNo ? new Size(filmSize.Width, filmSize.Height * (1 - headerScale)) : filmSize); var viewerControlBitmap = this.RenderViewerControlToBitmap(viewerControlSize, filmingPagePageControl, medViewerControl, ifSaveImageAsGreyScale); //判断title位置,决定是否截屏title,拼接两张图片生成最终胶片 var headerSize = new Size(viewerControlBitmap.PixelWidth, filmSize.Height * (ifHeaderSimple?headerScale:scale)); WriteableBitmap headerBitmap = null; WriteableBitmap filmpageBitmap = null; if (pageTitlePosition == "0" && !ifPageNo) //no film page bar { filmpageBitmap = viewerControlBitmap; Logger.LogFuncDown(); return(filmpageBitmap); } headerBitmap = this.RenderHeaderToBitmap(headerSize, ifHeaderSimple?filmingPageBarGridSimple:filmingPageBarGrid, ifSaveImageAsGreyScale); if (pageTitlePosition == "2") { filmpageBitmap = StitchBitmapsHorizontally(ifSaveImageAsGreyScale, viewerControlBitmap, headerBitmap); } else { filmpageBitmap = StitchBitmapsHorizontally(ifSaveImageAsGreyScale, headerBitmap, viewerControlBitmap); } Logger.LogFuncDown(); return(filmpageBitmap); } catch (Exception ex) { Logger.LogFuncException(ex.Message + ex.StackTrace); throw; } }