zoukankan      html  css  js  c++  java
  • 将图片转换成16进制的代码 dodo

    using   System.IO;   
    从图片写入文本文件! 
      private   void   button1_Click(object   sender,   System.EventArgs   e)  
      {  
      FileStream   fs   =     null;  
      BinaryReader   br   =   null;  
      StreamWriter   sw     =   null;  
       
      try  
      {  
       
      fs     =   new   FileStream("aa.bmp",FileMode.Open,FileAccess.Read);  
      br   =   new   BinaryReader(fs);  
      sw   =   new   StreamWriter("bb.txt");  
      int   length   =   (int)fs.Length;  
      while(length   >   0)  
      {  
      byte   tempByte   =   br.ReadByte();  
      int   tempInt   =Convert.ToInt32(tempByte);  
      string   tempStr   =   Convert.ToString(tempInt,16);  
              sw.WriteLine(tempStr);  
      length--;  
      }  
       
       
      }  
      catch(Exception   exce)  
      {  
      MessageBox.Show(exce.Message);  
      }  
      finally  
      {  
      sw.Close();  
      br.Close();  
      fs.Close();  
      }  
       
      }  
      从文本中读取,并还原成图片!  
      private   void   button2_Click(object   sender,   System.EventArgs   e)  
      {  
       
      FileStream   fs   =     null;  
              BinaryWriter   bw   =   null;  
              StreamReader   sr   =   null;  
      try  
      {  
      fs   =   new   FileStream("cc.bmp",FileMode.Create,FileAccess.Write);  
      bw   =   new   BinaryWriter(fs);  
      sr   =   new   StreamReader("bb.txt");  
      while(sr.Peek()   !=   -1)  
      {  
      string   tempStr   =   sr.ReadLine();  
      int   tempInt   =   Convert.ToInt16(tempStr,16);  
      byte   tempByte   =   Convert.ToByte(tempInt);  
      bw.Write(tempByte);  
      }  
       
      }  
      catch(Exception   exce)  
      {  
       
      MessageBox.Show(exce.Message);  
      }  
      finally  
      {  
      sr.Close();  
      bw.Close();  
      fs.Close();  
      }  
       
      }
  • 相关阅读:
    联想yoga table2 1371f 进入bios 的巧妙方法
    vs开发nodejs api文档生成神器-apidoc
    Android中文乱码彻底解决
    android图片处理方法(不断收集中)
    【Android开发】完美解决Android完全退出程序
    android自动打包方法(ant+proguard+签名)
    Android 访问权限设置记录-存档留着有用!
    [安卓开发]App Widget开发入门指导
    Android蓝牙操作笔记
    android 基于百度地图api开发定位以及获取详细地址
  • 原文地址:https://www.cnblogs.com/zgqys1980/p/581797.html
Copyright © 2011-2022 走看看