- 浏览: 400955 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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)
最新评论
with the transition from Winform to WPF, there is rising/upsurging demand to convert from System.Drawing.Icon to System.Media.ImageSource and vice versa (you cannot rule out the possibility to host new tech object in old ones)
Below shows how you can do to convert from System.Drwing.Icon to ImageSource.
internal static class IconUtilities { // you may refer to this page for details on how to convert from System.Drawing.Icon to System.Media.ImageSource // http://stackoverflow.com/questions/1127647/convert-system-drawing-icon-to-system-media-imagesource [DllImport("gdi32.dll", SetLastError = true)] private static extern bool DeleteObject(IntPtr hObject); public static ImageSource ToImageSource(this Icon icon) { Bitmap bitmap = icon.ToBitmap(); IntPtr hBitmap = bitmap.GetHbitmap(); ImageSource wpfBitmap = Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); if (!DeleteObject(hBitmap)) { throw new Win32Exception(); } return wpfBitmap; } }
note: the referenced material, contains more solution to do the conversion:
withou losing fairness, here is the code that uses the MemoryStream,
public static ImageSource ToImageSourceWithMemoryStream(this Icon icon) { using (System.IO.MemoryStream iconstream = new System.IO.MemoryStream()) { icon.Save(iconstream); iconstream.Seek(0, System.IO.SeekOrigin.Begin); return System.Windows.Media.Imaging.BitmapFrame.Create(iconstream); } }
And you may wonder how do we do the reverse, that is from System.Windows.Media.Imaging.ImageSource or one of its descendant class, that is called System.Windows.Media.Imaging.BitmapSource to System.Drawing.Bitmap...
Here is one code, however, please be noted, the code has not been fully testified, it may work as expected or it may not.
internal static class BitmapSourceUtilities { public static Bitmap ToBitmap(this BitmapSource imageSource, double width, double height) { double newwidthratio = width / (double)imageSource.PixelWidth; // have no idea why the calculation is as such double newheightratio = width * (double)imageSource.PixelHeight / (double)imageSource.PixelHeight / (double) imageSource.PixelWidth; BitmapSource transformedBitmapSource = new TransformedBitmap( imageSource, new ScaleTransform(newwidthratio, newheightratio) ); int bitmapwidth = transformedBitmapSource.PixelWidth; int bitmapheight = transformedBitmapSource.PixelHeight; int stride = bitmapwidth * (transformedBitmapSource.Format.BitsPerPixel + 7) / 8); byte[] bits = new byte[bitmapheight * stride]; transformedBitmapSource.CopyPixels(bits, stride, 0); // you may want to put the following code that has the unsafe compiler turned on.... unsafe { fixed (byte* pBits = bits) { IntPtr ptr = new IntPtr(pBits); System.Drawing.Bitmap bitmap = new Bitmap( bitmapwidth, bitmapheight, stride, System.Drawing.Imaging.PixelFormat.Format32bppArgb, ptr); return bitmap; } } } }
another note is that : The above code references the BitmapSource-Bitmap interop. you may find some boilerplat code that do grayscale and others..
note: synonym of rising..
climbing | |
Synonyms:
|
advancing, ascending, emerging, going up,growing, increasing, mounting, skyrocketing,soaring, spiraling, surging, upsurging |
发表评论
-
wpf - example to enhance ComboBox for AutoComplete
2014-09-19 15:56 1979first let’s see an example ... -
WPF – Virtualization – VirutalizationStackPanel and ItemsPanelTemplate
2013-08-05 21:55 1421Topic: WPF – Virtualization – ... -
wpf - BehaviorBase and one use examples
2013-06-18 18:41 1318Behavior is something that we ... -
WPF - Setting foreground color of Entire window
2013-06-13 16:00 1925You might as well as I would s ... -
WPF - Enhanced TabControl - TabControlEx aka Prerendering TabControl
2013-06-13 13:12 5337As an opening word, let's che ... -
wpf - ControlTemplate and AddLogicChild/RemoveLogicalChild
2013-06-10 15:42 1191Recently I was trying to debug ... -
wpf - default implicit style
2013-05-10 10:24 796We know that if you left out ... -
wpf - Style setter on the attached property
2013-05-08 14:54 2857I believe that you are familia ... -
wpf - specify enum values in xaml
2013-05-08 11:31 3592Many a situation you find tha ... -
wpf - IG xamDataGrid bind to XmlDataProvider with Xml Island
2012-12-18 14:28 1289Sometimes you may bind to some ... -
wpf - translate winform button/mouse event to wpf events
2012-12-12 17:37 2166It 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 1461The System.WIndows.Controls.Gri ... -
c# - Convert from System.Drawing.Image to System.WIndows.Media.ImageSource
2012-09-25 14:27 7421In Previous discussion, we have ... -
wpf - Get Effective DependencyProperty value on a DependencyObject
2012-08-28 19:05 1048As discussed in my previous pos ... -
wpf - Default(Theme) style and its DefaultStyleKey
2012-08-28 17:54 1392As dicsused in the subsection o ... -
wpf - Dependency Property Value Precedence
2012-08-28 18:56 886A dependency property to an Dep ... -
wpf - WPF TemplateBinding vs RelativeSource TemplatedParent
2012-08-28 14:20 3719This is a post that summarizes ... -
wpf - ICutomTypeDescriptor , PropertyDescriptor and its use in PropertyGrid
2012-08-28 14:04 3589The type ICustomTypeDe ... -
wpf - tips to convert UI controls in WPF/Silverlight/Winforms into a Bitmap
2012-08-27 17:44 985In previous discussion, we have ...
相关推荐
Table of Contents Preface, Notes, Licenses . . . . . . . . ....1. Licenses for Third-Party Components ....1.1. FindGTest.cmake License ....1.2. LPeg Library License ....1.3. LuaFileSystem Library License ....
Along the way, it covers how to embed the WebKit Web browser in your application, how to have your application use data from other installed applications (and vice versa!) or off the Internet, and ...
Along the way, it covers how to embed the WebKit Web browser in your application, how to have your application use data from other installed applications (and vice versa!) or off the Internet, and ...
Convert your Macintosh icons to Windows icons and vice versa. With IcoFX you can extract icons from other files, including Windows Vista and Macintosh files. You can easily work with multiple files ...
- ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFlexControl.Invalidate and can be overriden (it is possible now to catch all object invalidation calls). - FIX: The TFlexPanel....
What is this?...If you have previously installed it as system-wide and now you want it current user only (or vice-versa), it won't remove it, you must do it yourself. (at least for now)
but nothing for converting from Octal and Hex to decimal (correct us if we are wrong), or from binary to decimal and vice-versa. This sample code does just that. If you do any kind <END><br>55,...
// - To get a BufferedImage from an IplImage, or vice versa, we can chain calls to // Java2DFrameConverter and OpenCVFrameConverter, one after the other. // - Java2DFrameConverter also has static ...
In addition to XMLs, resources such as 9 patch images, layouts, strings and much more are correctly decoded to source form. Decoding The decode option on Apktool can be invoked either from d or ...
generate bitmaps from the compressed data and vice versa. It also provides for methods to access the meta data in the files, and methods to manipulate the Jpeg file in a lossless way (rotation/...
【淡色效果实现详解】 在计算机图形学中,淡入淡出效果,即从彩色渐变到灰度或反之,是一种常见的视觉过渡技术,广泛应用于图像处理、动画制作以及用户界面设计中。这种效果能够平滑地改变图像的视觉感受,增加动态...
This class is used to convert a GeoAPI Geometry to ESRI and vice-versa. It can also convert a ESRI Geometry to WKB/WKT and vice-versa.
generate bitmaps from the compressed data and vice versa. It also provides for methods to access the meta data in the files, and methods to manipulate the Jpeg file in a lossless way (rotation/...
几种常用文件类型相互转换。The #1 Converter tool that supports PDF, Word, Excel, PPT, JPG. Convert PDF to different formats and vice versa in one click.
I've also tried to include some C++ tips like how to convert strings to integers and vice versa. This isn't anything to do with TinyXML itself, but it may helpful for your project so I've put it in ...
Python can call MEL scripts and vice versa, allowing for seamless integration between the two languages. **Maya Python Standalone Applications** Developing standalone applications using Python and ...
The Kerberos protocol uses strong cryptography so that a client can prove its identity to a server (and vice versa) across an insecure network connection. After a client and server has used Kerberos ...
For example, "clusters" are defined by the file system, the allocation of clusters to files (and vice versa) is known to WinHex, "free space" and "slack space" have a meaning. If you need to edit ...
4)....Added "--el_injectjcl", "--el_createjcl", and "--el_createdbg" command-line options for ecc32/emake to inject JEDI/JCL debug info, create .jdbg file, and create .dbg file (Microsoft debug format...