zoukankan      html  css  js  c++  java
  • 图像类型的互转

      废话不说,直接码代码:

     1 static class ImageConverter
     2 {
     3     public static ImageSource ToImageSource(this Bitmap bitmap)
     4     {
     5         return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
     6     }
     7 
     8     public static BitmapSource ToBitmapSource(this Bitmap bitmap)
     9     {
    10         return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
    11     }
    12 
    13     public static Icon ToIcon(this Bitmap bitmap)
    14     {
    15         return Icon.FromHandle(bitmap.GetHicon());
    16     }
    17 
    18     public static Image ToImage(this Bitmap bitmap)
    19     {
    20         return Image.FromHbitmap(bitmap.GetHbitmap());
    21     }
    22 
    23     public static ImageSource ToImageSource(this Icon icon)
    24     {
    25         return System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
    26     }
    27 }
  • 相关阅读:
    Makefile 之 $(Q)
    LeetCode-50-Pow(x, n)
    LeetCode-49. Group Anagrams
    全排列问题全面解析
    LeetCode-47. Permutations II
    LeetCode-46. Permutations
    LeetCode-43. Multiply Strings
    LeetCode-40. Combination Sum II
    LeetCode-39. Combination Sum
    LeetCode-36. Valid Sudoku
  • 原文地址:https://www.cnblogs.com/Bita/p/5584460.html
Copyright © 2011-2022 走看看