标签:style blog http color os width
黄色的是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
wpf 保存控件中的内容为图片格式,布布扣,bubuko.com
标签:style blog http color os width
原文地址:http://www.cnblogs.com/tianyiwuying/p/3842498.html