- 浏览: 399725 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
Following the discussion on this topic that I previous published: Convert from System.Drawing.Icon to System.Media.ImageSource and vice versa , which we discussed the possibility to convert a System.Windows.Forms.Icon into WPF classes such as System.Media.ImageSource;
While there also exist some requirement to do the bridge for the classes such as Forms, or any other specific classes descendant from the System.Windows.Forms.Control class. One of such scenario exists when you say want to print the Visual of the Windows form control.
Fortunately the similar techinque exist for the Forms controls, because like the ICon class, all Form class has a DrawToBitMap method to draw the Control to a bit map, with which you can grab/grip/snatch and make a call to the System.Windows.Interop.Imaging.GetBitmapSourceFromHBitmap(Handle,..);
Please read for more information about the DrawToBitmap method,
Below show one example that use this very similar technique but on the general Forms controls.
public static ImageSource CreateImageSource(System.Windows.Forms.Control control, double width, double height) { System.Drawing.Bitmap b = new System.Drawing.Bitmap((int) width, (int) height); IntPtr bmpHandle = IntPtr.Zero; try { control.DrawToBitmap(b, new System.Drawing.Rectangle(0, 0, (int)width, (int)height); var imageSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( b.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, // Int32Rect.Empty to indicate all sourceRect to to draw? System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); return imageSource; } finally { if (bmpHandle != IntPtr.Zero) { NativeMethods.DeleteObject(bmpHandle); } } }
With the returned ImageSource, you can do a lot of things, including creating a ImageBrush, with wich you can paint to the DrawingContext.DrawRectangle or something. e.g. are
public static DrawingVisual CreateDrawingImage(System.Windows.Media.ImageSource imageSource, double width, double height) { var drawingVisual = new DrawingVisual(); // you can create the ImageBrush //var imageBrush = new ImageBrush(imageSource); // open the Render of the DrawingVisual using (var dc = drawingVisual.RenderOpen()) { var rectangle = new Rect { X = 0, Y = 0, Width = width, Height = height, }; // draw the white background dc.DrawRectangle(Brushes.White, null, rectangle); // if you create the ImageBrush, you can pain with the brush //dc.DrawRectangle(imageBrush, null, rectangle); dc.DrawImage(imageSource, rectangle); } return drawingVisual; }
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1976first let’s see an example ... -
WPF – Virtualization – VirutalizationStackPanel and ItemsPanelTemplate
2013-08-05 21:55 1410Topic: WPF – Virtualization – ... -
wpf - BehaviorBase and one use examples
2013-06-18 18:41 1311Behavior is something that we ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1918You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5330As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1185Recently I was trying to debug ... -
wpf - default implicit style
2013-05-10 10:24 794We know that if you left out ... -
wpf - Style setter on the attached property
2013-05-08 14:54 2851I believe that you are familia ... -
wpf - specify enum values in xaml
2013-05-08 11:31 3585Many a situation you find tha ... -
wpf - IG xamDataGrid bind to XmlDataProvider with Xml Island
2012-12-18 14:28 1286Sometimes you may bind to some ... -
wpf - translate winform button/mouse event to wpf events
2012-12-12 17:37 2162It is common that we sometimes ... -
wpf - Freezable and its meaning
2012-09-27 12:38 0This article is based on the di ... -
wpf - Customize the grid lines for original wpf Grid control
2012-09-27 12:01 1458The System.WIndows.Controls.Gri ... -
c# - Convert from System.Drawing.Image to System.WIndows.Media.ImageSource
2012-09-25 14:27 7417In Previous discussion, we have ... -
wpf - Get Effective DependencyProperty value on a DependencyObject
2012-08-28 19:05 1044As discussed in my previous pos ... -
wpf - Default(Theme) style and its DefaultStyleKey
2012-08-28 17:54 1387As dicsused in the subsection o ... -
wpf - Dependency Property Value Precedence
2012-08-28 18:56 882A dependency property to an Dep ... -
wpf - WPF TemplateBinding vs RelativeSource TemplatedParent
2012-08-28 14:20 3713This is a post that summarizes ... -
wpf - ICutomTypeDescriptor , PropertyDescriptor and its use in PropertyGrid
2012-08-28 14:04 3580The type ICustomTypeDe ... -
wpf - tips to convert UI controls in WPF/Silverlight/Winforms into a Bitmap
2012-08-27 17:44 975In previous discussion, we have ...
相关推荐
在本文中,我们将深入探讨"AI-wpf-controls",这是一个专为Windows Presentation Foundation(WPF)框架设计的控件库。这个独特的库整合了多个知名控件库的优点,包括MahApps.Metro、Material-Design、HandyControl...
通用WPF主题控件包rubyer-wpf-master是一款专为Windows Presentation Foundation (WPF) 应用程序设计的开源UI框架。它提供了丰富的主题和控件,旨在帮助开发者快速构建美观且用户友好的应用程序界面。在2.0.0版本中...
gong-wpf-dragdrop, GongSolutions.WPF.DragDrop 库是WPF的拖动'n'拖放框架 简介GongSolutions.WPF.DragDrop 库是一个易于使用的拖拉'n'拖放框架。特性使用 MVVM: 拖放逻辑可以放在ViewModel中。 代码不需要放在in中...
标题中的“wpf-mvvm-DeskTop-Sample-master”表明这是一个关于WPF(Windows Presentation Foundation)桌面应用程序的示例项目,使用了MVVM(Model-View-ViewModel)设计模式。这个项目是用C#编程语言编写的,面向的...
在这个名为"WPF-ControlBase-master.zip"的压缩包中,我们可以推测它包含了一个基于WPF的控制库项目,可能是一个开源或者个人开发的项目,用于提供自定义的WPF控件。这些控件可能是对标准WPF控件的扩展或增强,也...
Prism-Samples-Wpf-master11-15的VS2017版本实现,下载手动重新安装一下nuget包即可,方便大家学习
WPF的基本空间历程,使用.net core3.0.1版本
此程序从官网上下载的安装包,没有进行任何破解,如果要破解,看我另外一个资源ControlRegisterHelp那个
WPF-Diagram-Designer 是一个基于Windows Presentation Foundation (WPF)技术的开源项目,用于构建可自定义的图表设计工具。这个项目提供了一套完整的解决方案,帮助开发者创建交互式、可视化的设计界面,适用于流程...
在“Wpf-glTF-testing.zip”压缩包中,我们有一个基于WPF(Windows Presentation Foundation)的简化glTF文件查看器项目。 WPF是.NET Framework的一部分,是一个用于构建Windows桌面应用程序的框架。它提供了丰富的...
WPF Datagrid是WPF中一个重要的控件,用于显示和操作表格数据,类似于Windows Forms中的DataGridView。在这个“wpf-datagrid-access DB”主题中,我们将深入探讨如何利用WPF Datagrid与Microsoft Access数据库进行...
“wpf---StatusBar”这个标题表明我们将探讨的是WPF(Windows Presentation Foundation)框架中的StatusBar组件。WPF是.NET Framework的一部分,用于构建桌面应用程序,它提供了丰富的用户界面(UI)功能。StatusBar...
Windows Presentation Foundation (WPF) 是Microsoft开发的一个用于构建桌面应用程序的框架,它提供了丰富的图形系统,包括对2D和3D图形的强大支持。在WPF中,开发人员可以利用各种图表控件来创建可视化数据展示,这...
该资源"practical-wpf-charts-graphics-master.rar"包含了这本书的源代码,为读者提供了丰富的实践案例和深入理解WPF图表及图形编程的宝贵材料。 WPF(Windows Presentation Foundation)是.NET Framework的一部分...
WPF-进阶视频教程(共113集)-108在Windows窗体驻留WPF控件.mp4
本文将介绍如何快速添加新手引导功能到 WPF 项目中,采用 MVVM 模式,并使用开源项目 AIStudio.Wpf.Controls 的修改版本 9WPFControls 实现新手引导功能。下面将详细介绍如何使用 9WPFControls 添加新手引导功能。 ...
【标题】"WPF-JJDown-v1.234.0" 提示我们这是一个基于Windows Presentation Foundation(WPF)的应用程序,名为JJDown。版本号v1.234.0表明这是该软件的第1次重大更新,第234次次要更新或修复。这通常意味着它经历了...
**WPF-WCF-WF整合开发实例** WPF(Windows Presentation Foundation)、WCF(Windows Communication Foundation)和WF(Windows Workflow Foundation)是微软.NET框架中三个关键的技术组件,它们各自负责不同的领域...
WPF-进阶视频教程(共113集)-104与Windows窗体的交互.mp4