📄 unit1.~cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::myWriteFile(unsigned char *p,int num)
{int outFileHandle;
int i,j,k=-1; unsigned char tempchar[3000];
int l,xiangtong,butong,butongshu;
i=0;
while(i<=num-1)
{
if(i==num-1)
{tempchar[++k]=1;tempchar[++k]=p[i];break;}
for (xiangtong=1,j=i+1;(p[j]==p[i])&&(j<=num-1);j++)
{
++xiangtong;
if(xiangtong==254) {j++;break;}
}
if(j>i+1)
{tempchar[++k]=xiangtong;
tempchar[++k]=p[i];
i=j;
}
for ( butongshu=1,j=i+1;j<=num-1;j++)
{
butong=1;
for (l=i;l<=j-1;l++)
if(p[j]==p[l]){butong=0;break;}
if(butong==1)
{++butongshu;
if(butongshu==254) {j++;break;}
}
else break;
}
if(j>i+1)
{
tempchar[++k]=0;
tempchar[++k]=butongshu;
for(l=i;l<=i+butongshu-1;l++)
tempchar[++k]=p[l];
i=j;
}
}
outFileHandle=FileOpen(ChangeFileExt(Edit1->Text,".pcx"),fmOpenWrite);
FileSeek(outFileHandle,0,2);
if(FileWrite(outFileHandle,tempchar,(k+1))!=(k+1))
ShowMessage("写入文件出错");
FileClose(outFileHandle);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N2Click(TObject *Sender)
{
if(OpenDialog1->Execute())
{
Edit1->Text=OpenDialog1->FileName;
Image1->Picture->LoadFromFile(Edit1->Text);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N3Click(TObject *Sender)
{
int FileHandle,outFileHandle,FileLength;
int num;
unsigned char *pszBuffer;
int buf1=1024;
FileHandle=FileOpen(Edit1->Text,fmOpenRead);
FileLength=FileSeek(FileHandle,0,2);
Edit3->Text=AnsiString(FileLength)+"字节";
num=FileLength/buf1+1;
ProgressBar1->Max=num;
ProgressBar1->Position=1;
FileClose(FileHandle);
outFileHandle=FileCreate(ChangeFileExt(Edit1->Text,".pcx"));
FileClose(outFileHandle);
pszBuffer=new unsigned char[buf1];
int i=1;int temp=buf1;
for(i=1;i<=num;i++)
{ if(i==num)
{// delete [] pszBuffer;
pszBuffer=new unsigned char[FileLength-buf1*(num-1)];}
if(i==num) temp=FileLength-buf1*(num-1) ;
FileHandle=FileOpen(Edit1->Text,fmOpenRead);
FileSeek(FileHandle,buf1*(i-1),0);
if (FileRead(FileHandle,pszBuffer,temp)!=temp)
ShowMessage("读入文件错误");
FileClose(FileHandle);
myWriteFile(pszBuffer,temp);
ProgressBar1->Position=i;
// delete [] pszBuffer;
}
outFileHandle=FileOpen(ChangeFileExt(Edit1->Text,".pcx"),fmOpenWrite);
FileLength=FileSeek(outFileHandle,0,2);
Edit4->Text=AnsiString(FileLength)+"字节";
FileClose( outFileHandle);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Click(TObject *Sender)
{
if(OpenDialog2->Execute())
Edit2->Text=OpenDialog2->FileName;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N5Click(TObject *Sender)
{
int j,FileHandle,FileLength,outFileHandle;
unsigned char zz,*chartemp,*pszBuffer ,*desc;
FileHandle=FileOpen(Edit2->Text,fmOpenRead);
FileLength=FileSeek(FileHandle,0,2);
outFileHandle=FileCreate(ChangeFileExt(Edit2->Text,".bmp"));
FileClose(outFileHandle);
outFileHandle=FileOpen(ChangeFileExt(Edit2->Text,".bmp"),fmOpenReadWrite);
FileSeek(outFileHandle,0,0);
chartemp=new unsigned char [2];
pszBuffer=new unsigned char[2];
int m=0;
ProgressBar2->Max=FileLength/100;
// __int64 m=0;
while(m<=FileLength-1)
{ ProgressBar2->Position=m/100;
FileSeek(FileHandle,m,0);
FileRead(FileHandle,pszBuffer,1);
if(pszBuffer[0]==0)
{FileSeek(FileHandle,m+1,0);
FileRead(FileHandle,chartemp,1);
zz=chartemp[0];
desc=new unsigned char [zz+1];
FileSeek(FileHandle,m+2,0);
FileRead(FileHandle,desc,zz);
FileSeek(outFileHandle,0,2);
FileWrite(outFileHandle,desc,zz);
m=m+zz+2;
//delete []desc;
}
else
{desc=new unsigned char [pszBuffer[0]];
FileSeek(FileHandle,m+1,0);
FileRead(FileHandle,desc,1);
for (j=1;j<=pszBuffer[0]-1;j++)desc[j]=desc[0];
FileSeek(outFileHandle,0,2);
//for (j=1;j<=pszBuffer[0];j++)
FileWrite(outFileHandle,desc,pszBuffer[0]);
m=m+2;
// delete []desc;
}
}
FileClose( FileHandle);
// outFileHandle=FileOpen(ChangeFileExt(Edit2->Text,".111"),fmOpenRead);
FileLength=FileSeek(outFileHandle,0,2);
Edit5->Text=FileLength;
FileClose( outFileHandle);
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -