博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
WPF控件保存为图片Bitmap
阅读量:6966 次
发布时间:2019-06-27

本文共 1831 字,大约阅读时间需要 6 分钟。

#region  控件保存为图片--放大图        ///         /// 控件保存为图片--可处理放大图        ///         ///         /// 
public static Bitmap CreateNotRanderElementScreenshot(FrameworkElement element, double MatrixTransform=1) { var wantRanderSize = new System.Windows.Size(Math.Truncate(element.ActualWidth * MatrixTransform), Math.Truncate(element.ActualHeight * MatrixTransform)); element.Measure(wantRanderSize); element.SnapsToDevicePixels = true; element.Arrange(new Rect(new System.Windows.Point(0, 0), wantRanderSize)); return CreateElementScreenshot(element, Convert.ToInt32(Math.Truncate(element.ActualWidth * MatrixTransform)), Convert.ToInt32(Math.Truncate(element.ActualHeight * MatrixTransform))); } private static Bitmap CreateElementScreenshot(Visual visual, int sWidth, int sHeight) { RenderTargetBitmap bmp = new RenderTargetBitmap(sWidth, sHeight, 96, 96, PixelFormats.Default); //RenderTargetBitmap bmp = new RenderTargetBitmap((int)RenderSize.Width, (int)RenderSize.Height, 96, 96, PixelFormats.Default); bmp.Render(visual); Bitmap bitmap = new Bitmap(bmp.PixelWidth, bmp.PixelHeight, System.Drawing.Imaging.PixelFormat.Format32bppArgb); BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(System.Drawing.Point.Empty, bitmap.Size), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); bmp.CopyPixels(Int32Rect.Empty, data.Scan0, data.Height * data.Stride, data.Stride); bitmap.UnlockBits(data); //bitmap.Save(@"D:\TestCode\WpfDragMoveTest\SerialPortPrint\bin\Debug\5555.png", ImageFormat.Png); return bitmap; } #endregion

 

转载于:https://www.cnblogs.com/xunyiHe/p/10538910.html

你可能感兴趣的文章
【文件监控】之一:理解 ReadDirectoryChangesW part1
查看>>
Objective-C
查看>>
PyCharm搭建pyqt5开发环境
查看>>
微信小程序实战–集阅读与电影于一体的小程序项目(七)
查看>>
摄像机、投影、3D旋转、缩放
查看>>
给大家分享两款正在使用的ref“.NET研究”lector插件
查看>>
关于presentModalViewController的一点儿思考
查看>>
【128】Word中的VBA
查看>>
PowerCollections
查看>>
禁用gridview,listview回弹或下拉悬停
查看>>
FineReport报表和水晶报表的比较
查看>>
C++日志系统log4cxx使用总结
查看>>
Hadoop家族 路线图(转)
查看>>
[RxJS] Introduction to RxJS Marble Testing
查看>>
单例设计模式
查看>>
hadoop 日常问题汇总(持续更新)
查看>>
Atitit.一个cms有多少少扩展点,多少api wordpress  cms有多少api。。扩展点...
查看>>
使用C# + httpWebRequest 解析WMTS服务元数据
查看>>
帧中继网络 (转)
查看>>
Mac拷贝/复制文件夹路径快捷键
查看>>