📄 imgapp.~cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "imgApp.h"
#include "stdio.h"
#include <fstream.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
#define BUFFSIZE 1
#define szerokosc 160
#define wysokosc 160
TForm1 *Form1;
int con;
FILE *f,*fs;
int iRozmiar;
char bufor[8][szerokosc];
char bufor2[8][szerokosc];
char cos[1];
char *costam=cos;
DWORD dwBytesToWrite = 1;
DWORD dwBytesToRead = 1;
DWORD lpdwBytesWritten;
DWORD lpdwBytesReturned;
int run =0;
char c;
int bytes=0;
int buff_size=0;
int swaping = 0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
StatusBar1->Panels->Items[0]->Text = "Gotowy";
StatusBar1->Panels->Items[1]->Text = "Rozlaczony";
con = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{ if(con==1) return;
ProgressBar1->Position = 0;
ftStatus = FT_Open(DevNum,&ftHandle);
if (ftStatus != FT_OK){
StatusBar1->Panels->Items[1]->Text = "Blad !!!";
con = 0;
}
else{
StatusBar1->Panels->Items[1]->Text = "Polaczenie ustalone";
con = 1;
}
SendCounter = 0;
ReadCounter = 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button6Click(TObject *Sender)
{
if(con==0) return;
ProgressBar1->Position = 0;
ftStatus = FT_Close(ftHandle);
if (ftStatus != FT_OK)
StatusBar1->Panels->Items[1]->Text = "Blad";
else
StatusBar1->Panels->Items[1]->Text = "Rozlaczony";
con = 0;
SendCounter = 0;
ReadCounter = 0;
Label7->Caption = IntToStr(SendCounter);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ProgressBar1->Position = 0;
if(con==0){
StatusBar1->Panels->Items[1]->Text = "Najpierw sie polacz";
return;
}
run = 1;
String fileName;
if(OpenDialog1->Execute()){
fileName = OpenDialog1->FileName;
}
else return;
SendCounter = 0;
ReadCounter = 0;
Label7->Caption = IntToStr(SendCounter);
StatusBar1->Panels->Items[0]->Text = "Trwa liczenie....";
f = fopen(fileName.c_str(),"rb");
fs = fopen("wynik.raw","wb");
fseek(f, 0, SEEK_END);
iRozmiar = ftell(f);
fseek(f, 0, SEEK_SET);
dwBytesToWrite = 1;
dwBytesToRead = 1;
bytes=0;
Timer1->Enabled = true;
Label7->Caption = IntToStr(iRozmiar);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Timer1->Enabled = false;
Form1->Left = (Screen->Width - Form1->Width)/2;
Form1->Top = (Screen->Height - Form1->Height)/2;
}
//---------------------------------------------------------------------------
void TForm1::send_bmp()
{
int x,y,i,j,k,l,m;
for(y=0;y<wysokosc;y+=8)
{
fread(&bufor,sizeof(bufor),1,f);
for(x=0;x<szerokosc;x+=8)
{
for(i=0;i<8;i++)
{
for(j=0;j<8;j++)
{
cos[0]=bufor[i][x+j];
bytes++;
ftStatus = FT_Write(ftHandle,costam,dwBytesToWrite,&lpdwBytesWritten);
if(ftStatus == FT_OK)
{
SendCounter+=lpdwBytesWritten;
}
}
}
ProgressBar1->Position = 100*bytes/iRozmiar;
for(k=0;k<8;k++)
{
for(l=0;l<8;l++)
{
ftStatus = FT_Read(ftHandle,costam,dwBytesToRead,&lpdwBytesReturned);
if(ftStatus == FT_OK)
{
bufor2[k][l+x]=cos[0];
}
}
}
}
fwrite(bufor2,sizeof(bufor2),1,fs);
}
}
void TForm1::read_bmp(){
ProgressBar1->Position = 100*bytes/iRozmiar;
//if(bytes==iRozmiar)
{
run =0;
Timer1->Enabled = false;
StatusBar1->Panels->Items[0]->Text = "Zrobione";
fclose(f);
fclose(fs);
}
}
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(run == 1){
if(swaping==0){
send_bmp();
swaping = 1;
return;
}
else{
read_bmp();
swaping = 0;
}
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -