我想把d:\1.gif文件用流的方式写到e:\1.gif,代码如下,为什么生成的文件跟原来的不一样:
var
sf,sf1:TStream;
buffer: array[0..1023] of byte ;
i,C,c1,len :integer;
begin
len := 1024; //每次读写1024长度
try
sf:=TFileStream.Create('d:\1.gif',fmOpenRead);
sf1:=TFileStream.Create('e:\1.gif',fmCreate);
c := sf.Size;
c1 := c;
c := c1 div len;
i := c1 mod len;
if i > 0 then c := c + 1; for i := 1 to c do
begin
if i = c then
begin
sf.Seek(((i - 1) * len),soFromEnd);
sf.Read(buffer,c1 - (i - 1) * len);
sf1.Write(Buffer,c1 - (i - 1) * len);
end
else
begin
sf.Seek((i - 1 * len),soFromEnd);
sf.Read(buffer,len);
sf1.Write(Buffer,len);
end;
end;
finally
sf1.Free;
sf1 := nil;
sf.free;
sf:=nil;
end;
var
sf,sf1:TStream;
buffer: array[0..1023] of byte ;
i,C,c1,len :integer;
begin
len := 1024; //每次读写1024长度
try
sf:=TFileStream.Create('d:\1.gif',fmOpenRead);
sf1:=TFileStream.Create('e:\1.gif',fmCreate);
c := sf.Size;
c1 := c;
c := c1 div len;
i := c1 mod len;
if i > 0 then c := c + 1; for i := 1 to c do
begin
if i = c then
begin
sf.Seek(((i - 1) * len),soFromEnd);
sf.Read(buffer,c1 - (i - 1) * len);
sf1.Write(Buffer,c1 - (i - 1) * len);
end
else
begin
sf.Seek((i - 1 * len),soFromEnd);
sf.Read(buffer,len);
sf1.Write(Buffer,len);
end;
end;
finally
sf1.Free;
sf1 := nil;
sf.free;
sf:=nil;
end;
解决方案 »
- 自定义Font对话框
- 用dbgrideh如何使其只能从picklist中选择数据,而不能输入数据?
- fastreport 修改报表时菜单怎么全是2378、2379等数字啊,不现实中文的菜单。
- 选中listview中的一个item后,当鼠标点击该listview之外的地方时,如何让listview中的item取消选中?
- 关于打开窗体的问题
- 那位兄弟有381纸的打印机,给作个测试,老板让做好但是没有打印机没有办法测试,谢谢了,在线急等
- delphi 7 中的注释不能用汉字?
- 数据库高手请进:错误信息没有指示器变量
- 为什么form的宽最小只能112
- Delphi5.0开发的SQL数据库系统的分发
- 关于tcpsokcet连接的问题
- 用MSCOMM控件向rs232输出7B 09 00 01 43 4C 4F 43 4B 2A A0 7D
还有else情况下 i-1*len ,不知道不是不原来你就是那么写的