当前位置: 首页 > news >正文

广州天河做网站中咨城建设计有限公司 网站

广州天河做网站,中咨城建设计有限公司 网站,网站设计模板之家,个人承接网站开发服务文章目录 前言一、如何实现#xff1f;1、制作无边框窗口2、Viewbox放大3、截屏显示#xff08;1#xff09;、截屏#xff08;2#xff09;、转BitmapSource#xff08;3#xff09;、显示 4、定时截屏 二、完整代码三、效果预览总结 前言 做桌面截屏功能时需要放大镜… 文章目录 前言一、如何实现1、制作无边框窗口2、Viewbox放大3、截屏显示1、截屏2、转BitmapSource3、显示 4、定时截屏 二、完整代码三、效果预览总结 前言 做桌面截屏功能时需要放大镜显示鼠标所在位置的放大图像在wpf中使用Bursh的ViewBox属性可以实现图像放大桌面的画面则需要截屏了总的来说还是比较容易实现的。 一、如何实现 1、制作无边框窗口 推荐使用WindowChrome Window Background{x:Null} ResizeModeNoResize WindowStyleNoneWindowChrome放在Window 标签内 WindowChrome.WindowChromeWindowChrome GlassFrameThickness-1 CaptionHeight0 / /WindowChrome.WindowChrome2、Viewbox放大 定义一个Ellipse 控件作为放大镜Viewbox默认为相对单位即范围时0-1值越小放大比例越大 Ellipse StrokeLightBlueEllipse.FillImageBrush x:Nameib Viewbox0,0,0.5,0.5 //Ellipse.Fill /Ellipse3、截屏显示 1、截屏 参考《C# wpf 使用GDI实现截屏》里的简单截屏即完成。获取的数据类型为Bitmap。 2、转BitmapSource 参考《C# wpf Bitmap转换成WriteableBitmapBitmapSource的方法》将Bitmap转换为转换成wpf对象。 3、显示 获取到BitmapSource给控件赋值即可。 //显示到界面 ib.ImageSource wb;4、定时截屏 显示桌面必然需要实时的画面所以需要定时截屏。 //启动定时器截屏 var dispatcherTimer new DispatcherTimer() { Interval TimeSpan.FromMilliseconds(33), }; dispatcherTimer.Tick (s, e) {//截屏并显示 }; dispatcherTimer.Start();二、完整代码 完整代码依赖System.Drawing添加引用方法可以参考《C# wpf 使用GDI实现截屏》。 MainWindow.xaml Window x:ClassWpfMagnifier.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfMagnifiermc:IgnorabledBackground{x:Null}ResizeModeNoResizeWindowStyleNoneShowInTaskbarFalseTopmostTrueTitleMainWindow Height200 Width200 MouseLeftButtonDownWindow_MouseDownWindowChrome.WindowChromeWindowChrome GlassFrameThickness-1 CaptionHeight0 //WindowChrome.WindowChromeEllipse StrokeLightBlueEllipse.FillImageBrush x:Nameib Viewbox0,0,0.5,0.5 //Ellipse.Fill/Ellipse /WindowMainWindow.xaml.cs using System; using System.Windows; using System.Windows.Input; using System.Windows.Media.Imaging; using System.Windows.Threading; namespace WpfMagnifier {/// summary/// Interaction logic for MainWindow.xaml/// /summarypublic partial class MainWindow : Window{public MainWindow(){InitializeComponent();//启动定时器截屏var dispatcherTimer new DispatcherTimer() { Interval TimeSpan.FromMilliseconds(33), };dispatcherTimer.Tick (s, e) {//gdi截屏截取窗口左边的区域可根据具体使用场景调整截屏位置,使用PointToScreen消除dpi影响var leftTop PointToScreen(new Point(-Width, 0));var rightBottom PointToScreen(new Point(0, Height));var bm Snapshot((int)leftTop.X, (int)leftTop.Y, (int)(rightBottom.X - leftTop.X), (int)(rightBottom.Y - leftTop.Y));var wb BitmapToWriteableBitmap(bm);//显示到界面ib.ImageSource wb;};dispatcherTimer.Start();}private void Window_MouseDown(object sender, MouseButtonEventArgs e){DragMove();}/// summary/// 截取一帧图片/// /summary/// param namexx坐标/param/// param nameyy坐标/param/// param namewidth宽/param/// param nameheight高/param/// returns截屏后的位图对象需要调用Dispose手动释放资源。/returnspublic static System.Drawing.Bitmap Snapshot(int x, int y, int width, int height){System.Drawing.Bitmap bitmap new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);using (System.Drawing.Graphics graphics System.Drawing.Graphics.FromImage(bitmap)){graphics.CopyFromScreen(x, y, 0, 0, new System.Drawing.Size(width, height), System.Drawing.CopyPixelOperation.SourceCopy);}return bitmap;}//将Bitmap 转换成WriteableBitmap public static WriteableBitmap BitmapToWriteableBitmap(System.Drawing.Bitmap src){var wb CreateCompatibleWriteableBitmap(src);System.Drawing.Imaging.PixelFormat format src.PixelFormat;if (wb null){wb new WriteableBitmap(src.Width, src.Height, 0, 0, System.Windows.Media.PixelFormats.Bgra32, null);format System.Drawing.Imaging.PixelFormat.Format32bppArgb;}BitmapCopyToWriteableBitmap(src, wb, new System.Drawing.Rectangle(0, 0, src.Width, src.Height), 0, 0, format);return wb;}//创建尺寸和格式与Bitmap兼容的WriteableBitmappublic static WriteableBitmap CreateCompatibleWriteableBitmap(System.Drawing.Bitmap src){System.Windows.Media.PixelFormat format;switch (src.PixelFormat){case System.Drawing.Imaging.PixelFormat.Format16bppRgb555:format System.Windows.Media.PixelFormats.Bgr555;break;case System.Drawing.Imaging.PixelFormat.Format16bppRgb565:format System.Windows.Media.PixelFormats.Bgr565;break;case System.Drawing.Imaging.PixelFormat.Format24bppRgb:format System.Windows.Media.PixelFormats.Bgr24;break;case System.Drawing.Imaging.PixelFormat.Format32bppRgb:format System.Windows.Media.PixelFormats.Bgr32;break;case System.Drawing.Imaging.PixelFormat.Format32bppPArgb:format System.Windows.Media.PixelFormats.Pbgra32;break;case System.Drawing.Imaging.PixelFormat.Format32bppArgb:format System.Windows.Media.PixelFormats.Bgra32;break;default:return null;}return new WriteableBitmap(src.Width, src.Height, 0, 0, format, null);}//将Bitmap数据写入WriteableBitmap中public static void BitmapCopyToWriteableBitmap(System.Drawing.Bitmap src, WriteableBitmap dst, System.Drawing.Rectangle srcRect, int destinationX, int destinationY, System.Drawing.Imaging.PixelFormat srcPixelFormat){var data src.LockBits(new System.Drawing.Rectangle(new System.Drawing.Point(0, 0), src.Size), System.Drawing.Imaging.ImageLockMode.ReadOnly, srcPixelFormat);dst.WritePixels(new Int32Rect(srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height), data.Scan0, data.Height * data.Stride, data.Stride, destinationX, destinationY);src.UnlockBits(data);}} }三、效果预览 显示的是窗口放大镜左边的画面 总结 以上就是今天要讲的内容本文仅仅简单介绍了实现桌面放大镜的方法关键在于使用Viewbox截屏的功能因为有现成的所以比较简单当然本文的方法是简单实现其实还是可以优化的尤其是截屏是可以复用Bitmap对象的。总的来说wpf实现桌面放大镜还是比较容易的而且效果也很不错。
http://www.zqtcl.cn/news/912629/

相关文章:

  • wordpress页面构建器中文文山seo公司
  • 凡科免费做网站蜂箱尺寸与制作图片
  • 完全不收费的聊天软件班级优化大师下载安装app
  • 合肥网站改版360免费建站永久免费
  • 商业网站建设案例课程 下载工信部企业网站认证
  • 泉州网站设计哪家公司好沈阳seo代理计费
  • 做景观素材有哪几个网站国内建网站费用
  • 驻马店重点项目建设网站wordpress常规选项
  • 网站开发 英文网站策划建设阶段的推广
  • 建立网站一般多少钱wordpress评论跳过验证
  • 南京每月做社保明细在哪个网站查看设计作品的网站软件
  • html怎么做网站如何在腾讯云上网站建设
  • 网站建设怎么链接表格手机做外贸有什么好的网站
  • 深圳开发网站建设哪家好外贸网络营销培训
  • 广州智迅网络做网站免费下载ps素材网站
  • 什么网站时候做伪静态开发软件定制
  • 找人做网站 多少钱西宁市公司网站建设
  • 网页设计 教程网站找权重高的网站方法
  • 网站建设本地还是外地重庆seo排名方法
  • 那个网站做网编好昨晚兰州发生了什么事
  • 温州建设局网站首页哪里可以学做资料员的网站
  • 网站怎样在360做优化wordpress文章图片在线裁剪
  • 彭州建设网站建设网站哪间公司比较好
  • qq空间网站根目录慧聪网首页
  • 制作小程序和网站的公司杭州品牌设计公司
  • 显示网站翻页代码wordpress 金融 模板下载
  • 用双语网站做seo会不会phpmysql网站
  • 长沙专业网站建设公司优惠券怎么做自己的网站
  • 做网站如何宣传怎么弄公众号
  • seo网站策划书网站建设资金投入