Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:2k
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include <stdio.h>
- #pragma hdrstop
- #include "Unit1.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- unsigned char c;
- char ss[10];
- int ct=0,ii,nn;
- TFileStream * fm;
- TMemoryStream * Msm;
- fm=new TFileStream("bmp.txt",fmCreate);
- Msm = new TMemoryStream();
- Image1->Picture->Bitmap->SaveToStream(Msm);
- Msm->Position=0;
- nn=Msm->Size;
- for(ii=0;ii<nn;ii++)
- {
- Msm->Read(&c,1);
- sprintf(ss,"%.2x",c);
- fm->Write(ss,2);
- ct++;
- if(ct>40)
- {
- ct=0;
- ss[0]=0x0d;ss[1]=0x0a;
- fm->Write(ss,2);
- }
- }
- ss[0]=0x0d;ss[1]=0x0a;
- fm->Write(ss,2);
- delete Msm;
- delete fm;
- }
- //---------------------------------------------------------------------------
- AnsiString TForm1::Read2Byte(TStream *sm)
- {
- char ss[4];
- int ii,ll;
- unsigned char c;
- ii=0;ss[0]=0;
- for(;;)
- {
- ll=sm->Read(&c,1);
- if(ll<1)return "END";
- if((c!=0x0d)&&(c!=0x0a))
- {
- ss[ii]=c;ii++;
- if(ii>1){ss[ii]=0;break;}
- }
- }
- return (AnsiString)ss;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- unsigned char c;
- AnsiString ass;
- char ss[2];
- ss[1]=0;
- TFileStream * fm;
- TMemoryStream * Msm;
- fm=new TFileStream("bmp.txt",fmOpenRead);
- Msm = new TMemoryStream();
- for(;;)
- {
- ass=Read2Byte(fm);
- if(ass=="END")break;
- sscanf(ass.c_str(),"%x",&c);
- ss[0]=c;
- Msm->Write(ss,1);
- // buff.c_str()[ii]=c;
- // ii++;
- }
- Msm->Position=0;
- Image2->Picture->Bitmap->LoadFromStream(Msm);
- delete Msm;
- delete fm;
- }
- //---------------------------------------------------------------------------