首页 > 代码库 > 图像形式转换
图像形式转换
//图形转换 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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。