zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    Maven安装以及Idea安装
    EasyUi和jQuery模拟后台管理页面
    EasyUI初级入门2
    EasyUI初级入门
    JS高级
    好用的表单验证工具 vuelidate
    为页面/接口添加加载进度条
    Nuxt.js(二、解决首屏速度与SEO)
    Nuxt 的介绍与安装
    Axios及其async await封装
  • 原文地址:https://www.cnblogs.com/tianyiwuying/p/3842498.html
Copyright © 2011-2022 走看看