zoukankan      html  css  js  c++  java
  • 图像形式转换

         //图形转换  Bitmap=>Image
            private System.Windows.Controls.Image Bitmap2Image(System.Drawing.Bitmap Bi)
            {
                MemoryStream ms = new MemoryStream();
                Bi.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                BitmapImage bImage = new BitmapImage();
                bImage.BeginInit();
                bImage.StreamSource = new MemoryStream(ms.ToArray());
                bImage.EndInit();
                ms.Dispose();
                Bi.Dispose();
                System.Windows.Controls.Image i = new System.Windows.Controls.Image();
                i.Source = bImage;
                return i;
            }
         //ImageSource给WPF的Image控件设置图片地址
            private System.Windows.Media.ImageSource ConvertDrawingImage2MediaImageSource(System.Drawing.Image image)
            {
                var ms = new MemoryStream();
    
                var bitmap = new System.Windows.Media.Imaging.BitmapImage();
                bitmap.BeginInit();
    
                image.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                ms.Seek(0, System.IO.SeekOrigin.Begin);
                bitmap.StreamSource = ms;
                bitmap.EndInit();
                return bitmap;
            }
            //将16进制字符串转成Byte[],这样可以使用MemoryStream来构建图片
            private byte[] strToToHexByte(string hexString)
            {
                hexString = hexString.Replace(" ", "");
                if ((hexString.Length % 2) != 0)
                    hexString += " ";
                byte[] returnBytes = new byte[hexString.Length / 2];
                for (int i = 0; i < returnBytes.Length; i++)
                    returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
                return returnBytes;
            }
  • 相关阅读:
    Mysql推荐使用规范
    程序员应该经常浏览的技术网站
    百度,腾讯,阿里等互联网公司年终奖发多少
    JNI技术详解,让程序有飞一般的感觉
    日志:分布式系统的核心
    Spring Boot七:Spring boot集成MyBatis
    通俗理解TCP的三次握手
    JDBC添加数据
    JDBC概念
    今天是阳光明媚的一天
  • 原文地址:https://www.cnblogs.com/9527y/p/3793323.html
Copyright © 2011-2022 走看看