图像形式转换

摘要:
//图形转换Bitmap=˃ImageprivateSystem。窗户。控制。ImageBitmap2Image(System.Drawing.BitmapBi){MemoryStreamms=newMemoryStream();Bi.Save(ms,System.Drawing.Imagin.ImageFormat.Png);BitmapImagebImage=n
     //图形转换  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;
        }

免责声明:文章转载自《图像形式转换》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Databricks 第5篇:Databricks文件系统(DBFS)WPF概述下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C#调用Axis2发布的带SoapHeader用户验证的WebService

起因:合作公司提供了一个WebService供我调用,为了保证安全性,要求在SoapHeader中带用户名和密码进行校验。 在获取了对方的WSDL文件后,并未在文件中指明SoapHeader的格式以及要传递的用户名、密码的属性名称。按照C#中调用WebService的常规方法,在测试工程中“添加Web引用”或“添加服务引用”,只看到生成的*.discoma...

在Linux上运行C#

众所周知,C#是Microsoft推出的.NET语言,只能在.NET平台上运行,例如Win 9x、ME、NT、2000、XP和Win CE之类的操作系统。但是,现在却有了一个叫做Mono的项目,它的目标就是把.NET及其编程语言移植到非Windows的平台上。现在,C#是唯一被移植到非Windows平台的.NET语言。   在任何一个平台(操作系统+硬件体...

关于.Net中使用SQLite数据库的方法

参考: SQLite之C#连接SQLite https://www.cnblogs.com/icebutterfly/p/7850689.html 关于SQLite的库安装比较特殊: 下载地址:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki --ok! htt...

c# 获取相对路径

c# 获取相对路径 一、获取当前文件的路径1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName获取模块的完整路径,包括文件名。2. System.Environment.CurrentDirectory获取和设置当前目录(该进程从中启动的目录)的完全限定目录。3. Sy...

windows-System权限获取任意用户权限目录-举例GetTempPath

目录 一丶简介 二丶代码 一丶简介 在System权限启动我们的程序之后.如果程序内部使用了GetTempPath()函数.或者使用了其它跟用户权限有关的函数.则获取的路径不是你想要的.比如 你在System权限下使用了GetTempPath() 那么获取的temp路径有可能就是 "C:WindowsTemp" 而我们想要获取的路径则是 "C:...

Vue实现图片预加载

<script>export default { data () { return { count: 0, } }, mounted: function() { this.preload() }, methods: { preload: function() { let imgs = [ "static/img/back.gif", "sta...