• wpf 保存控件中的内容为图片格式


              黄色的是wpf控件的名称!

             //保存到特定路径
                FileStream fs = new FileStream(@"C:image.png", FileMode.Create);
                //对象转换成位图
                RenderTargetBitmap bmp = new RenderTargetBitmap((int)this.mediaElement1.ActualWidth, (int)this.mediaElement1.ActualHeight, 100, 100, PixelFormats.Pbgra32);
                bmp.Render(this.mediaElement1);
                //对象的集合编码转成图像流
                BitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(bmp));
                //保存到路径中
                encoder.Save(fs);
                //释放资源
                fs.Close();
                fs.Dispose();

    //第二个截取全屏

        Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
                Graphics g = Graphics.FromImage(myImage);
                g.CopyFromScreen(new Point(0, 0), new Point(0, 0), new Size(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height));
                IntPtr dc1 = g.GetHdc(); //此处这两句多余,具体看最后GetHdc()定义
                g.ReleaseHdc(dc1);
                g.Dispose();          
                 myImage.Save(@"C:image.png",System.Drawing.Imaging.ImageFormat.Png);

    原作者  http://blog.sina.com.cn/s/blog_8bf5ef0d01013wli.html

  • 相关阅读:
    vue 侦听器
    vue 计算属性
    typeof 运算符
    constructor 属性
    立即执行函数与闭包
    计算属性缓存 vs 方法
    JavaScrip备课
    winform 实现对usb热拔插的监听
    c# async await的使用方式及为啥要用它
    .net5与之前的版本GetBytes长度变化
  • 原文地址:https://www.cnblogs.com/tianyiwuying/p/3842498.html
Copyright © 2020-2023  润新知