//----引入必要的命名空间
using System.IO;
using System.Drawing.Imaging;

//----代码部分----//

private byte[] photo;//公用缓冲区
public string SourFilePath;//源图片文件路径
public string ObjFilePath;//目标图片路径

public int FileToStream()//文件到流的转换
{
Image img = new Bitmap(SourFilePath);
MemoryStream stream = new MemoryStream();
img.Save(stream, ImageFormat.Bmp);
BinaryReader br = new BinaryReader(stream);
photo = stream.ToArray();
stream.Close();
return 0;
}

public Image ShowPic()//根据流显图
{
byte[] bytes = photo;
MemoryStream ms = new MemoryStream(bytes);
ms.Position = 0;
Image img = Image.FromStream(ms);
ms.Close();
return img;
}

public int StreamToFile()//反向转换
{
byte[] bytes = photo;
FileStream fs = new FileStream(ObjFilePath, FileMode.Create, FileAccess.Write);
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
return 0;
}

最新文章

  1. Android 和 H5 通信
  2. css中的选择器
  3. gcc杂谈
  4. 解决xshell连接linux总是异常断开的问题?
  5. cocos2d-x jsbinding 资源下载实现
  6. 如何保护 .NET 应用的安全?
  7. 转:Oracle EBS FND User Info API
  8. Android代码混淆
  9. mock server相关解决方案
  10. CakePHP下使用paginator需要对多个字段排序的做法
  11. 将ArrayList<HashMap<String, String>>转为ArrayList<Bundle>类型的解决方案
  12. centos搭建java web服务器
  13. Stanford CS224N 第二课: word2vec详细介绍
  14. android动画介绍--Animation 实现loading动画效果
  15. git简介及安装(win10)
  16. Table 'performance_schema.session_status' doesn't exist错误,解决办法
  17. kafka安装和部署
  18. SQL Server 表分区备忘
  19. create table b1 as select * from b建表锁表测试
  20. OPENSSL编程起步

热门文章

  1. UVA-11248 Frequency Hopping (最大流+最小割)
  2. IOS-多线程(NSOperation)
  3. windows配置Scrapy爬虫框架
  4. jQuery实现鼠标经过图片预览大图效果
  5. windows下jenkins安装过程中的那些坑
  6. 利用python完成多个url状态码的检测
  7. 第11课 enum,sizeof,typedef分析
  8. ZetCode PyQt4 tutorial basic painting
  9. python线程的GIL问题(全局解释器锁)
  10. 常用PHP框架收集