WPF中的Bitmap与byte
public MainWindow()
{
InitializeComponent();
byte[] b = GetPictureData(@"F:\WPF\TestSolution\TestReatByteFromDB\Images\123.png");
BitmapImage myimg = ByteArrayToBitmapImage(b);
this.testImg.Source = myimg;
} public byte[] GetPictureData(string imagepath)
{
/**/
////根据图片文件的路径使用文件流打开,并保存为byte[]
FileStream fs = new FileStream(imagepath, FileMode.Open);//可以是其他重载方法
byte[] byData = new byte[fs.Length];
fs.Read(byData, 0, byData.Length);
fs.Close();
return byData;
} public BitmapImage ByteArrayToBitmapImage(byte[] byteArray)
{
BitmapImage bmp = null; try
{
bmp = new BitmapImage();
bmp.BeginInit();
bmp.StreamSource = new MemoryStream(byteArray);
bmp.EndInit();
}
catch
{
bmp = null;
} return bmp;
} public byte[] BitmapImageToByteArray(BitmapImage bmp)
{
byte[] byteArray = null; try
{
Stream sMarket = bmp.StreamSource; if (sMarket != null && sMarket.Length > 0)
{
//很重要,因为Position经常位于Stream的末尾,导致下面读取到的长度为0。
sMarket.Position = 0; using (BinaryReader br = new BinaryReader(sMarket))
{
byteArray = br.ReadBytes((int)sMarket.Length);
}
}
}
catch
{
//other exception handling
} return byteArray;
}
WPF中的Bitmap与byte的更多相关文章
- Android中Bitmap, Drawable, Byte,ID之间的转化
Android中Bitmap, Drawable, Byte,ID之间的转化 1. Bitmap 转化为 byte ByteArrayOutputStream out = new ByteArray ...
- 浅谈WPF中对控件的位图特效(WPF Bitmap Effects)
原文:浅谈WPF中对控件的位图特效(WPF Bitmap Effects) -------------------------------------------------------------- ...
- C#中Image , Bitmap 和 BitmapData
先说Image,Image 就是个图像,不能实例化,提供了位图和源文件操作的函数.本篇文章他就是来打酱油的,这里提供一个Bitmap转成BitmapSource的方法. [DllImport(&quo ...
- Android-Drawable、Bitmap、byte[]、资源文件相互转换
我们在Android的开发中,经常可以遇到图片的处理,当中,有很多是 Bitmap.Drawable.byte[]和资源文件它们直接相互转换. 今天就此总结一下: 1.资源文件转为Drawable 2 ...
- Android Drawable、Bitmap、byte[]之间的转换
转自http://blog.csdn.net/june5253/article/details/7826597 1.Bitmap-->Drawable Bitmap drawable2Bitma ...
- 基于C#在WPF中使用斑马打印机进行打印【转】
原文链接:http://ju.outofmemory.cn/entry/132476 最近在项目中接手了一个比较有挑战性的模块——用斑马打印机将需要打印的内容打印出来.苦苦折腾了两天,总算有所收获,就 ...
- WPF中的image控件的Source赋值
WPF中的Image控件Source的设置 1.XAML中 简单的方式(Source="haha.png"); image控件的Source设置为相对路径后(Source=&quo ...
- WPF中实现验证码功能
其实和winform中的实现差不多,只是由于WPF中控件使用的库与winform中的有区别,大体上还是差不多的,直接看代码: 产生验证码的类:ValidCode.cs public class Val ...
- GMap.Net开发之在WinForm和WPF中使用GMap.Net地图插件
GMap.NET是什么? 来看看它的官方说明:GMap.NET is great and Powerful, Free, cross platform, open source .NET contro ...
随机推荐
- Python 基于python+mysql浅谈redis缓存设计与数据库关联数据处理
基于python+mysql浅谈redis缓存设计与数据库关联数据处理 by:授客 QQ:1033553122 测试环境 redis-3.0.7 CentOS 6.5-x86_64 python 3 ...
- macos 下安装brew
1.终端执行 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master ...
- [20171124]xxd与通配符.txt
[20171124]xxd与通配符.txt --//linux 上许多命令都支持通配符,比如$ ls -l *.txt-rw-r--r-- 1 oracle oinstall 44801024 201 ...
- sql server递归
with cte as ( select belongsAgent from [QPProxyDB].[dbo].[BS_ProxyInfo] where ProxyID = @ProxyID uni ...
- centos7下rsync+crontab定期同步备份
最近需求想定期备份内部重要的服务器数据到存储里面,顺便做个笔记 以前整过一个win下的cwrsync(客户端)+rsync(服务端:存储)的bat脚本 这次整一个Linux下的脚本sh,执行定期自动备 ...
- Django框架的使用教程--类视图-中间间-模板[六]
类视图 类视图的使用 视图函数 class class_view(View): """类视图""" def get(self, reques ...
- 使用Jenkins+gitlab自动化构建时排除分支
我们的目的是gitlab上的代码有变动时会自动向Jenkins发送web钩子请求,触发指定的动作: 但默认情况下,所有分支(如测试环境和预生产)的代码有变动时都会触发,此时可以在Jenkins的项目设 ...
- row_number() over() 一句话概括,以及max()函数的一种查询分组中最大值的用法
row_number() over(partition by col1 order by col2) 根据COL1分组可能会有多个组,每组组内根据COL2进行排序.每组内都有自动生成的序号,从1开始, ...
- Java设计模式之八 ----- 责任链模式和命令模式
前言 在上一篇中我们学习了结构型模式的享元模式和代理模式.本篇则来学习下行为型模式的两个模式, 责任链模式(Chain of Responsibility Pattern)和命令模式(Command ...
- vue-cli 打包后显示favicon.ico小图标
第一步:favicon.ico小图标放在static里面 第二步:index.html 文件中引入时需要写 ./ 相对路径 第三部:npm run build 打包 打包完成就可以看到 favicon ...