zoukankan      html  css  js  c++  java
  • WPF RenderTargetBitmap保存UIElement内容为空问题

    对UIElement进行刷新

    Size tSize = new Size(tPenNode.Width, tPenNode.Height);
    tPenNode.Measure(tSize);
    tPenNode.Arrange(new Rect(new Point(0, 0), tSize));
    
    DrawingVisual tDrawingVisual = new DrawingVisual();
                using (DrawingContext context = tDrawingVisual.RenderOpen())
                {
                    VisualBrush tVisualBrush = new VisualBrush(tPenNode);
                    tVisualBrush.Stretch = Stretch.Fill;
                    context.DrawRectangle(tVisualBrush, null, new Rect(0, 0, 80, 80));
                    context.Close();
                }
    
                RenderTargetBitmap tRenderTargetBitmap = new RenderTargetBitmap(80,80, 96, 96, PixelFormats.Default);
                tRenderTargetBitmap.Render(tDrawingVisual);
    
                using (FileStream tFileStream = new FileStream("C:\\1.png",
                                            FileMode.Create, FileAccess.Write))
                {
    
                    PngBitmapEncoder tPngBitmapEncoder = new PngBitmapEncoder();
                    tPngBitmapEncoder.Interlace = PngInterlaceOption.On;
                    tPngBitmapEncoder.Frames.Add(BitmapFrame.Create(tRenderTargetBitmap));
                    tPngBitmapEncoder.Save(tFileStream);
                    tFileStream.Close();
                }
    

      

  • 相关阅读:
    react-路由简单封装
    promise 和 async / await
    数据结构 栈 、 队列 、 链表
    ES6 Symbol
    react-react常用包与对应使用
    node-egg的使用
    自我理解与概述-BFC(Block formatting context)
    Git
    MySQL优化技巧
    Shiro
  • 原文地址:https://www.cnblogs.com/sunhappy0318/p/2657929.html
Copyright © 2011-2022 走看看