• 图像形式转换


         //图形转换  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;
            }
  • 相关阅读:
    ASP.NET 4.0的ClientIDMode属性
    关于sql链接超时的问题
    Image.Url 无法使用 Server.MapPath(使用后无论如何也不显示)
    C# 中字符串转换成日期
    Linux RAID 磁盘管理
    脚本编写
    挂载一个NFS共享
    配置NFS服务
    配置多用户SMB挂载
    通过 SMB 共享目录
  • 原文地址:https://www.cnblogs.com/9527y/p/3793323.html
Copyright © 2020-2023  润新知