zoukankan      html  css  js  c++  java
  • 转:将图片转换成16进制的代码写入文本

    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();   
      }
       
        
      }
     
  • 相关阅读:
    程序集“xxx"中的类型"xxx"的方法“XXXX”没有实现
    关于C# json转object时报错:XXXXXXXXXX需要标记“"”,但找到“XX”。
    System.Reflection.Assembly.GetEntryAssembly()获取的为当前已加载的程序集
    MongoDB 模糊查询,及性能测试
    SignalR介绍与Asp.net,前台即时通信【转】
    mongodb常用命令【转】
    MongoDB update数据语法【转】
    Mongodb在Windows下安装及配置 【转】
    C#(asp.net)备份还原mssql数据库代码【转】
    小记,取GB2312汉字的首字母【转】
  • 原文地址:https://www.cnblogs.com/wuliang/p/982346.html
Copyright © 2011-2022 走看看