谁帮我把这段C++BUILDER的代码给改成DLEPHI,麻烦了,我改出来有点问题。(分不多了,在线等,谢谢了) (30分)

C

cjsam

Unregistered / Unconfirmed
GUEST, unregistred user!
这段代码是有个Image和Memo控件,先将他们的内容写成一个文件。而Image里的图片是黑白
两色的。其中Memo限定为100个字节
{
String str=".//aa.out";
FILE *f1;
int i,j,k;
unsigned int c;

f1=fopen(str.c_str(),"wb");
//1
if(f1){
for(i=0;i<Image1->Height;i++){
for(j=0;j<Image1->Width/8;j++){
c=0;
for(k=0;k<8;k++){
c=c*2;
if(Image1->Canvas->Pixels[j*8+k]==RGB(0,0,0)) c=c+1;
else c=c+0;
}
fwrite(&c,1,1,f1);
}
}

fwrite(Memo1->Text.c_str(),1,strlen(Memo1->Text.c_str()),f1);
if(strlen(Memo1->Text.c_str())<100){
c=0;
for(i=0;i<432-strlen(Memo1->Text.c_str());i++) fwrite(&c,1,1,f1);
}
}
fclose(f1);
 
帮忙看看!该一下呀
 
自己就可以改呀,{-begin,}-end,for i:=0 to Image1.Height-1,if-if then,=-:=,其余
都差不多呀
 
主要是地址,写文件那部分
 
好像不一样啊,你用到的文件函数好像是C的输入输出函数,DELPHI里好像没有这些函数,
 
DELPHI里有Readln,writeln,试着去改写一下吧,(只是一个建议)
 
我知道呀,就是改的有问题,谁帮我改一下
 
是不是因为这段程序写的太差啦 没人愿意翻呀,30分也太少了 :-)
var
f: TextFile
str: String;
i, j, k, w: integer;
c: word;
begin
str := './aa.out';
assert(FileExists(str));
AssignFile(f, str); //suppose the file alread exists
Append(f);
try
w := Image1.Width div 8;
for i:=0 to Image1.Height-1 do
begin
for j := 0 to w-1 do
begin
c=0;
for k := 0 to 8-1 do
begin
c := c*2;
if (Image1.Canvas.Pixels[j*8+k] = RGB(0,0,0)) do
inc(c)
end;
writeln(f, IntToStr(c));
end;
end;

writeln(f, Memo1.Text);

if Length(Memo1.Text) < 100 then
c := 0
for i := 0 to (432-Length(Memo1.Text)-1) do
begin
writeln(f, IntToStr(c));
end;
finally
close(f);
end;
end;
 
To Tintin,不好意思分是有点少,不过好象你该的有点问题。主要是追加文件
var
f: TextFile
str: String;
i, j, k, w: integer;
c: word;
begin
str := './aa.out';
assert(FileExists(str));
AssignFile(f, str); //suppose the file alread exists
Append(f);
try
w := Image1.Width div 8;
for i:=0 to Image1.Height-1 do
begin
for j := 0 to w-1 do
begin
c=0;
for k := 0 to 8-1 do
begin
c := c*2;
if (Image1.Canvas.Pixels[j*8+k] = RGB(0,0,0)) do
inc(c)
end;
//========================================
writeln(f, IntToStr(c));
//=========================================
end;
end;
//=======================
writeln(f, Memo1.Text);
//========================
if Length(Memo1.Text) < 100 then
c := 0
for i := 0 to (432-Length(Memo1.Text)-1) do
begin
//================================
writeln(f, IntToStr(c));
//=================================
end;
finally
close(f);
end;
end;
并不是只是追加到一个文件里,他是把图片(黑白单色)的写到一个文件里,
图片的大小是固定的。好象我试你这样写有点问题。
能还再帮我看一下嘛?
 
大概翻译的...

const
str : String = './aa.out';
var
f1 : file;
i, j, k : Integer;
c : word;
s : string;
begin
AssignFile(f1, str);
Rewrite(f1, str);

for i := 0 to Image1.Height-1 do
begin
for j := 0 to Image1.Width div 8 do
begin
c := 0;
for k := 0 to 7 do
begin
c := c*2;
if Image1.Canvas.Pixels[j*8+k,i]=RGB(0,0,0) then Inc(c);
end;
BlockWrite(f1, c, SizeOf(c));
end;
end;

s := Memo1.Text;
BlockWrite(f1, S[1], Length(S));

if Length(S) < 100 then
begin
c := 0;
for i := 0 to 432-Length(S) do
begin
BlockWrite(f1, c, SizeOf(c));
end
end;

CloseFile(f1);
end;

 
多人接受答案了。
 
顶部