当前位置: 首页>>代码示例>>C#>>正文


C# RenderTargetBitmap.Clear方法代码示例

本文整理汇总了C#中System.Windows.Media.Imaging.RenderTargetBitmap.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# RenderTargetBitmap.Clear方法的具体用法?C# RenderTargetBitmap.Clear怎么用?C# RenderTargetBitmap.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.Imaging.RenderTargetBitmap的用法示例。


在下文中一共展示了RenderTargetBitmap.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RenderTile

        void RenderTile(RenderTargetBitmap renderBitmap, int w, int h) {
// Measure and arrange the surface
            // VERY IMPORTANT
            var size = new Size(w, h);
            _graphCanvas.Measure(size);
            _graphCanvas.Arrange(new Rect(size));
            renderBitmap.Clear();
            renderBitmap.Render(_graphCanvas);
        }
开发者ID:matthagenbuch,项目名称:automatic-graph-layout,代码行数:9,代码来源:GraphmapsViewer.cs

示例2: _CreateImage

        /// <summary>
        /// Creates image from canvas with map background.
        /// </summary>
        /// <param name="mapImage">Map image.</param>
        /// <param name="canvas">Canvas to draw.</param>
        /// <returns>Created image.</returns>
        private Image _CreateImage(MapImage mapImage, SysControls.Canvas canvas)
        {
            Debug.Assert(null != mapImage);
            Debug.Assert(null != canvas);

            Image imageWithData = null;

            RenderTargetBitmap bmp = null;
            SysControls.Canvas outer = null;

            Image sourceImage = null;
            using (MemoryStream sourceStream = new MemoryStream((byte[])mapImage.ImageData))
                sourceImage = Image.FromStream(sourceStream);

            try
            {

                var bitmap = sourceImage as Bitmap;
                Debug.Assert(null != bitmap);
                ImageBrush imageBrush = _CreateImageBrush(bitmap);

                outer = new SysControls.Canvas();

                outer.Width = mapImage.ImageWidth;
                outer.Height = mapImage.ImageHeight;
                outer.Children.Add(canvas);
                outer.Background = (ImageBrush)imageBrush.GetCurrentValueAsFrozen();
                outer.Arrange(new Rect(0, 0, outer.Width, outer.Height));

                bmp = new RenderTargetBitmap((int)outer.Width,
                                             (int)outer.Height,
                                             mapImage.ImageDPI,
                                             mapImage.ImageDPI,
                                             PixelFormats.Pbgra32);
                bmp.Render(outer);

                var encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));

                using (MemoryStream stream = new MemoryStream())
                {
                    encoder.Save(stream);
                    imageWithData = Image.FromStream(stream);
                }
            }
            finally
            {   // Clear and dispose all used stuff
                if (outer != null)
                {
                    outer.UpdateLayout();
                    outer.Children.Clear();
                }

                canvas.UpdateLayout();
                foreach (object child in canvas.Children)
                {
                    var symbolControl = child as SymbolControl;
                    if (symbolControl != null)
                        symbolControl.Template = null;
                }
                canvas.Children.Clear();

                if (bmp != null)
                    bmp.Clear();

                if (sourceImage != null)
                    sourceImage.Dispose();
            }

            return imageWithData;
        }
开发者ID:erindm,项目名称:route-planner-csharp,代码行数:77,代码来源:MapImageExporter.cs

示例3: RenderIcon

        public System.Drawing.Bitmap RenderIcon(string iconText)
        {
            var text = new FormattedText(
                iconText,
                this.CultureInfo,
                this.FlowDirection,
                this.typeface,
                this.fontSize,
                this.foreground);

            var drawingVisual = new DrawingVisual();
            var drawingContext = drawingVisual.RenderOpen();
            drawingContext.DrawText(text, new Point(2, 2));
            drawingContext.Close();

            var target = new RenderTargetBitmap(
                this.iconSize,
                this.iconSize,
                TrayIconDPI,
                TrayIconDPI,
                PixelFormats.Default);

            target.Clear();
            target.Render(drawingVisual);

            var enc = new PngBitmapEncoder();
            enc.Frames.Add(BitmapFrame.Create(target));

            using (var ms = new MemoryStream())
            {
                enc.Save(ms);
                ms.Position = 0;

                return (System.Drawing.Bitmap)System.Drawing.Bitmap.FromStream(ms);
            }
        }
开发者ID:qzcw,项目名称:nbfc,代码行数:36,代码来源:TrayIconRenderer.cs

示例4: frameThread_DoWork

        void frameThread_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw = (BackgroundWorker)sender;

             MediaPlayer myPlayer = new MediaPlayer();
             myPlayer.Open(parameters.SourceUri);
             myPlayer.Volume = 0;
             myPlayer.Play();

             while (myPlayer.NaturalVideoWidth < 1)
            System.Threading.Thread.Sleep(100);

             myState = ScallopSensorState.Active;
             this.StatusChanged(this, new ScallopSensorStatusChangedEventArgs(ScallopSensorState.Idle, ScallopSensorState.Active));

             RenderTargetBitmap rtb = new RenderTargetBitmap(myPlayer.NaturalVideoWidth, myPlayer.NaturalVideoHeight,
                                                           96, 96, PixelFormats.Pbgra32);

             while (true)
             {
            if (bw.CancellationPending == true)
            {
               myPlayer.Stop();
               e.Cancel = true;
               return;
            }

            DrawingVisual dv = new DrawingVisual();
            DrawingContext dc = dv.RenderOpen();

            dc.DrawVideo(myPlayer, new Rect(0, 0, myPlayer.NaturalVideoWidth, myPlayer.NaturalVideoHeight));
            dc.Close();

            rtb.Clear();
            rtb.Render(dv);

            BitmapFrame bmp = BitmapFrame.Create(rtb);

            switch (parameters.FrameFormat)
            {
               case ("System.Drawing.Bitmap"):

                  using (MemoryStream memoryStream = new MemoryStream())
                  {
                     //bitmapEncoder.Frames.Add(BitmapFrame.Create(bmp));
                     PngBitmapEncoder bitmapEncoder = new PngBitmapEncoder();
                     bitmapEncoder.Frames.Add(bmp);
                     bitmapEncoder.Save(memoryStream);
                     memoryStream.Flush();

                     using (Bitmap bmp2 = Bitmap.FromStream(memoryStream) as Bitmap,
                                   bmp3 = new Bitmap(bmp2.Width,bmp2.Height,System.Drawing.Imaging.PixelFormat.Format24bppRgb))
                     {
                        bmp3.SetResolution(bmp2.HorizontalResolution, bmp2.VerticalResolution);

                        using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp3))
                        {
                           g.DrawImage(bmp2, 0, 0);
                        }

                        if (this.Data != null)
                           this.Data(this, new ScallopSensorDataEventArgs((System.Drawing.Bitmap)bmp3.Clone(), "new frame"));
                     }

                  }
                  break;

               case ("System.Windows.Media.Imaging.BitmapSource"):
                  if (this.Data != null)
                     this.Data(this, new ScallopSensorDataEventArgs(bmp as BitmapSource, "new frame"));
                  break;
            }

            if (myPlayer.Position >= myPlayer.NaturalDuration)
            {
               myPlayer.Stop();
               myPlayer.Position = TimeSpan.Zero;
               myPlayer.Play();
            }
             }
        }
开发者ID:MisterTobi,项目名称:scallop-framework,代码行数:81,代码来源:ScallopFileSource.cs


注:本文中的System.Windows.Media.Imaging.RenderTargetBitmap.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。