WPF中bitmapimage与byte[]格式相互转换
来源:互联网 发布:沼泽人思想实验知乎 编辑:程序博客网 时间:2024/06/04 20:12
byte[]转换为bitmapimage:
public static 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;
}
{
bitmapimage bmp = null;
try
{
bmp = new bitmapimage();
bmp.begininit();
bmp.streamsource = new memorystream(bytearray);
bmp.endinit();
}
catch
{
bmp = null;
}
return bmp;
}
bitmapimage转换为byte[]:
public static 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;
}
{
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中bitmapimage与byte[]格式相互转换
- bitmapimage与byte[]相互转换
- WPF(C#)中Bitmap与BitmapImage相互转换
- bitmapimage与byte[]相互转换 --转
- WPF BitmapImage与byte[]的转换
- WPF Image控件 Source: Byte[] ,BitmapImage 相互转换
- GDI+ Bitmap与WPF BitmapImage的相互转换
- WriteableBitmap/BitmapImage/MemoryStream/byte[]相互转换
- BitMapImage与byte[]之间的转换
- 【C#/WPF】Bitmap、BitmapImage、ImageSource 、byte[]转换问题
- byte[]转换为BitmapImage:
- .Net 中string与byte[]相互转换
- WP8 中常用的 WriteableBitmap和BitmapImage相互转换
- 图像相关(三) Bitmap与byte[]、BitmapImage与byte[]互相转换、图像加载与保存
- Bitmap与byte[]相互转换
- 图片与byte[]相互转换
- Base64与byte[]相互转换
- byte[]与string相互转换
- Domino开发者入门地图
- 系统超时跳转至首页解决
- C# 调用DLL
- 深入理解Aireplay-ng各种攻击及其原理
- Spring中操作applicationContext.xml
- WPF中bitmapimage与byte[]格式相互转换
- 没有实践,当然没有机会
- java I/O流,输入流,输出流,输入输出流,InputStream,FileInputStream,文件流,byte,url
- Qt 类型编辑实例-指定QPushButton 菜单指示器的子控制
- winpe下硬盘不存在,自动安装恢复ghost不存在
- 软件实施顾问的基本技能和需求控制
- 三角函数
- 列表ul的基本用法分析
- 好产品的简洁之道