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

手机php网站开发济南城市建设职业学院官网招生网

手机php网站开发,济南城市建设职业学院官网招生网,热点新闻事件100字,学校网站设计思路WPF开发者QQ群#xff1a; 340500857 | 微信群 - 进入公众号主页 加入组织欢迎转发、分享、点赞、在看#xff0c;谢谢~。 前言有小伙伴需要在软件反馈窗体增加截图功能需求#xff0c;所以今天来实现一个仿微信的截图。01—效果预览效果预览#xff08;更多效果请下…  WPF开发者QQ群 340500857  | 微信群 - 进入公众号主页 加入组织欢迎转发、分享、点赞、在看谢谢~。  前言      有小伙伴需要在软件反馈窗体增加截图功能需求所以今天来实现一个仿微信的截图。01—效果预览效果预览更多效果请下载源码体验02—代码如下一、ScreenCut.cs 代码如下using Microsoft.Win32; using System; using System.Collections.Generic; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes;namespace WPFDevelopers.Controls {[TemplatePart(Name CanvasTemplateName, Type typeof(Canvas))][TemplatePart(Name RectangleLeftTemplateName, Type typeof(Rectangle))][TemplatePart(Name RectangleTopTemplateName, Type typeof(Rectangle))][TemplatePart(Name RectangleRightTemplateName, Type typeof(Rectangle))][TemplatePart(Name RectangleBottomTemplateName, Type typeof(Rectangle))][TemplatePart(Name BorderTemplateName, Type typeof(Border))][TemplatePart(Name WrapPanelTemplateName, Type typeof(WrapPanel))][TemplatePart(Name ButtonSaveTemplateName, Type typeof(Button))][TemplatePart(Name ButtonCancelTemplateName, Type typeof(Button))][TemplatePart(Name ButtonCompleteTemplateName, Type typeof(Button))]public class ScreenCut : Window{private const string CanvasTemplateName PART_Canvas;private const string RectangleLeftTemplateName PART_RectangleLeft;private const string RectangleTopTemplateName PART_RectangleTop;private const string RectangleRightTemplateName PART_RectangleRight;private const string RectangleBottomTemplateName PART_RectangleBottom;private const string BorderTemplateName PART_Border;private const string WrapPanelTemplateName PART_WrapPanel;private const string ButtonSaveTemplateName PART_ButtonSave;private const string ButtonCancelTemplateName PART_ButtonCancel;private const string ButtonCompleteTemplateName PART_ButtonComplete;private Canvas _canvas;private Rectangle _rectangleLeft, _rectangleTop, _rectangleRight, _rectangleBottom;private Border _border;private WrapPanel _wrapPanel;private Button _buttonSave,_buttonCancel, _buttonComplete;private Rect rect;private Point pointStart, pointEnd;private bool isMouseUp false;static ScreenCut(){DefaultStyleKeyProperty.OverrideMetadata(typeof(ScreenCut), new FrameworkPropertyMetadata(typeof(ScreenCut)));}public override void OnApplyTemplate(){base.OnApplyTemplate();_canvas GetTemplateChild(CanvasTemplateName) as Canvas;_rectangleLeft GetTemplateChild(RectangleLeftTemplateName) as Rectangle;_rectangleTop GetTemplateChild(RectangleTopTemplateName) as Rectangle;_rectangleRight GetTemplateChild(RectangleRightTemplateName) as Rectangle;_rectangleBottom GetTemplateChild(RectangleBottomTemplateName) as Rectangle;_border GetTemplateChild(BorderTemplateName) as Border;_wrapPanel GetTemplateChild(WrapPanelTemplateName) as WrapPanel;_buttonSave GetTemplateChild(ButtonSaveTemplateName) as Button;if (_buttonSave ! null)_buttonSave.Click _buttonSave_Click;_buttonCancel GetTemplateChild(ButtonCancelTemplateName) as Button;if (_buttonCancel ! null)_buttonCancel.Click _buttonCancel_Click;_buttonComplete GetTemplateChild(ButtonCompleteTemplateName) as Button;if (_buttonComplete ! null)_buttonComplete.Click _buttonComplete_Click;this._canvas.Background new ImageBrush(ChangeBitmapToImageSource(CaptureScreen()));_rectangleLeft.Width _canvas.Width;_rectangleLeft.Height _canvas.Height;}private void _buttonSave_Click(object sender, RoutedEventArgs e){SaveFileDialog dlg new SaveFileDialog();dlg.FileName $WPFDevelopers{DateTime.Now.ToString(yyyyMMddHHmmss)}.jpg;dlg.DefaultExt .jpg;dlg.Filter image file|*.jpg;if (dlg.ShowDialog() true){BitmapEncoder pngEncoder new PngBitmapEncoder();pngEncoder.Frames.Add(BitmapFrame.Create(CutBitmap()));using (var fs System.IO.File.OpenWrite(dlg.FileName)){pngEncoder.Save(fs);fs.Dispose();fs.Close();}}Close();}private void _buttonComplete_Click(object sender, RoutedEventArgs e){Clipboard.SetImage(CutBitmap());Close();}CroppedBitmap CutBitmap(){var renderTargetBitmap new RenderTargetBitmap((int)_canvas.Width,(int)_canvas.Height, 96d, 96d, System.Windows.Media.PixelFormats.Default);renderTargetBitmap.Render(_canvas);return new CroppedBitmap(renderTargetBitmap, new Int32Rect((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height));}private void _buttonCancel_Click(object sender, RoutedEventArgs e){Close();}protected override void OnPreviewKeyDown(KeyEventArgs e){if (e.Key Key.Escape)Close();}protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e){if (!isMouseUp){_wrapPanel.Visibility Visibility.Hidden;pointStart e.GetPosition(_canvas);pointEnd pointStart;rect new Rect(pointStart, pointEnd);}}protected override void OnPreviewMouseMove(MouseEventArgs e){if (e.LeftButton MouseButtonState.Pressed !isMouseUp){var current e.GetPosition(_canvas);MoveAllRectangle(current);}}protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e){if (!isMouseUp){_wrapPanel.Visibility Visibility.Visible;Canvas.SetLeft(this._wrapPanel, rect.X rect.Width - this._wrapPanel.ActualWidth);Canvas.SetTop(this._wrapPanel, rect.Y rect.Height 4);isMouseUp true;}}void MoveAllRectangle(Point current){pointEnd current;rect new Rect(pointStart, pointEnd);this._rectangleLeft.Width rect.X;this._rectangleLeft.Height _canvas.Height;Canvas.SetLeft(this._rectangleTop, this._rectangleLeft.Width);this._rectangleTop.Width rect.Width;double h 0.0;if (current.Y pointStart.Y)h current.Y;elseh current.Y - rect.Height;this._rectangleTop.Height h;Canvas.SetLeft(this._rectangleRight, this._rectangleLeft.Width rect.Width);this._rectangleRight.Width _canvas.Width - (rect.Width this._rectangleLeft.Width);this._rectangleRight.Height _canvas.Height;Canvas.SetLeft(this._rectangleBottom, this._rectangleLeft.Width);Canvas.SetTop(this._rectangleBottom, rect.Height this._rectangleTop.Height);this._rectangleBottom.Width rect.Width;this._rectangleBottom.Height _canvas.Height - (rect.Height this._rectangleTop.Height);this._border.Height rect.Height;this._border.Width rect.Width;Canvas.SetLeft(this._border, rect.X);Canvas.SetTop(this._border, rect.Y);}System.Drawing.Bitmap CaptureScreen(){var bmpCaptured new System.Drawing.Bitmap((int)SystemParameters.PrimaryScreenWidth, (int)SystemParameters.PrimaryScreenHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb);using (System.Drawing.Graphics g System.Drawing.Graphics.FromImage(bmpCaptured)){g.SmoothingMode SmoothingMode.AntiAlias;g.CompositingQuality CompositingQuality.HighQuality;g.InterpolationMode InterpolationMode.HighQualityBicubic;g.TextRenderingHint TextRenderingHint.ClearTypeGridFit;g.PixelOffsetMode PixelOffsetMode.HighQuality;g.CopyFromScreen(0, 0, 0, 0, bmpCaptured.Size, System.Drawing.CopyPixelOperation.SourceCopy);}return bmpCaptured;}[System.Runtime.InteropServices.DllImport(gdi32.dll)]public static extern bool DeleteObject(IntPtr hObject);ImageSource ChangeBitmapToImageSource(System.Drawing.Bitmap bitmap){IntPtr hBitmap bitmap.GetHbitmap();ImageSource wpfBitmap System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap,IntPtr.Zero,Int32Rect.Empty,BitmapSizeOptions.FromEmptyOptions());if (!DeleteObject(hBitmap)){throw new System.ComponentModel.Win32Exception();}return wpfBitmap;}} }二、ScreenCut.xaml 代码如下 ResourceDictionary xmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:controlsclr-namespace:WPFDevelopers.ControlsResourceDictionary.MergedDictionariesResourceDictionary SourceBasic/ControlBasic.xaml/ResourceDictionary Source../Styles/Styles.Buttons.xaml//ResourceDictionary.MergedDictionariesStyle x:KeyRectangleStyle TargetType{x:Type Rectangle}Setter PropertyFill Value{StaticResource BlackSolidColorBrush}/Setter PropertyOpacity Value.5/ /StyleStyle TargetType{x:Type controls:ScreenCut} BasedOn{StaticResource ControlBasicStyle}Setter PropertyWindowState ValueMaximized/Setter PropertyWindowStyle ValueNone/Setter PropertyTemplateSetter.ValueControlTemplate TargetType{x:Type controls:ScreenCut}Canvas x:NamePART_CanvasWidth{Binding Source{x:Static SystemParameters.PrimaryScreenWidth}}Height{Binding Source{x:Static SystemParameters.PrimaryScreenHeight}}Rectangle x:NamePART_RectangleLeft Style{StaticResource RectangleStyle}/Rectangle x:NamePART_RectangleTop Style{StaticResource RectangleStyle}/Rectangle x:NamePART_RectangleRight Style{StaticResource RectangleStyle}/Rectangle x:NamePART_RectangleBottom Style{StaticResource RectangleStyle}/Border x:NamePART_Border BorderBrush{StaticResource SuccessPressedSolidColorBrush} BorderThickness1/WrapPanel x:NamePART_WrapPanel VisibilityHidden Panel.ZIndex99Height38 Background{StaticResource WhiteSolidColorBrush}VerticalAlignmentCenterButton x:NamePART_ButtonSave Style{StaticResource PathButton}ToolTip保存 Margin10,0,0,0Button.ContentPath Fill{StaticResource InfoPressedSolidColorBrush} Width18 Height18 StretchFill Data{StaticResource PathSave}//Button.Content/ButtonButton x:NamePART_ButtonCancel Style{StaticResource PathButton}ToolTip取消Button.ContentPath Fill{StaticResource DangerPressedSolidColorBrush} Width14 Height14 StretchFill Data{StaticResource PathCancel}//Button.Content/ButtonButton x:NamePART_ButtonComplete Style{StaticResource PathButton}ToolTip完成 Margin0,0,10,0Button.ContentPath Fill{StaticResource SuccessPressedSolidColorBrush} Width20 Height15 StretchFill Data{StaticResource PathComplete}//Button.Content/Button/WrapPanel/Canvas/ControlTemplate/Setter.Value/Setter /Style /ResourceDictionary三、ScreenCutExample.xaml 代码如下var screenCut new ScreenCut();screenCut.ShowDialog();源码地址githubhttps://github.com/yanjinhuagood/WPFDevelopers.gitgiteehttps://gitee.com/yanjinhua/WPFDevelopers.gitWPF开发者QQ群 340500857 blogs https://www.cnblogs.com/yanjinhuaGithubhttps://github.com/yanjinhuagood出处https://www.cnblogs.com/yanjinhua版权本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。转载请著名作者 出处 https://github.com/yanjinhuagood
http://www.yutouwan.com/news/409167/

相关文章:

  • 厦门做网站哪家强王烨乐清
  • 张家界建设网站的公司工程建设标准化网站
  • 网站下方一般放什么百度网址大全官网下载
  • 拨号地址怎么做网站国内做进口的电商网站
  • 查询个人信息的网站怎么在百度推广
  • 建设银行网站打不开怎么办海鲜网站模板
  • 汕头做网站优化公司免费备案域名
  • 快速搭建网站软件wordpress实例教程
  • 托管网站是什么意思昆明软件开发公司
  • 邯郸现代建设集团网站怎样学做网站运营
  • 加强理想信念教育主题网站建设百度关键词竞价价格查询
  • 别人的抖音网站是怎么做的北京app制作公司
  • 网上免费注册qq网站高端网站设计官网
  • 网站seo推广计划广东东莞智通人才招聘网
  • 网站建设win2012本地部署iis部署网站
  • 专门做创意桌椅的网站wordpress 主题logo
  • 珠海 电商 网站建设安康市集约化平台
  • 网站发布服务托管器建网站要服务器
  • 做网站赚不了钱海南海口网站开发公司
  • 给个人建网站的公司东坑镇仿做网站
  • 上海市网站建设公叿济源网站开发
  • 花都网站建设网页设计深圳宝安美容医院网站建设
  • 宁波高端网站设计厂家游戏网站设计
  • 网站建设模板网站网页设计素材图片大全
  • 网站二级菜单是什么意思wordpress 加下载
  • c 网站开发案例详解下载建设单位经常去哪个网站
  • 怎么用别人网站做模板专业网站建设科技公司
  • 学php做网站临沂百度网站建设
  • wordpress html文件优化大师app下载
  • 做图片详情网站软件开发设备清单