
22.08.2009, 00:17
|
|
Moderator - Level 7
Регистрация: 02.05.2009
Сообщений: 894
Провел на форуме: 4297091
Репутация:
2261
|
|
DiSi
Код:
program PicToTxt;
uses
SysUtils;
var
picture1: file of char;
picture2:textfile;
txt_file:textfile;
i:integer;
chr:char;
hex_chr:string[2];
buff:widestring;
{functions}
function ChrToHex(S: Char): String;
begin
Result:= IntToHex(ord(S),2);
end;
function HexToChr(H: String): Char;
begin
Result:= Char(StrToInt('$'+Copy(H,1,2)));
end;
{program start}
begin
{convert pic->txt}
buff:='';
assignfile(picture1,'c:\avata.gif');
reset(picture1);
for i:=1 to filesize(picture1) do
begin
read(picture1,chr);
buff:=buff+ChrToHex(chr);
end;
closefile(picture1);
assignfile(txt_file,'c:\txt_file.txt');
rewrite(txt_file);
write(txt_file,buff);
closefile(txt_file);
{convert txt->pic}
buff:='';
assignfile(txt_file,'c:\txt_file.txt');
reset(txt_file);
while not EOF(txt_file) do
begin
read(txt_file,hex_chr);
chr:=HexToChr(hex_chr);
buff:=buff+chr;
end;
closefile(txt_file);
assignfile(picture2,'c:\avata2.gif');
rewrite(picture2);
write(picture2,buff);
closefile(picture2);
end.
код подходит для обработки небольших файлов(не только картинок), для б0льших - вместо widestring (в качестве буффера) надо будет, конечно, использовать что-нибудь по-серьёзнее
Последний раз редактировалось ErrorNeo; 22.08.2009 в 03:50..
|
|
|