我用filestream对字节一个一个的操作速度太慢了
-----------------------
这样做的效率确实比较低,可以改进一下,定义一个缓冲区,先读数据到缓冲区,对缓冲区每字节左移两位后,再更新到文件,代码示例如下:
const
BUFFER_SIZE=1024*64;
var
buf:array[0..BUFFER_SIZE-1] of Byte;
nBytes:Integer;
I:Integer;
begin
with TFileStream.Create('C:/ABC.BMP',fmOpenReadWrite,fmShareDenyWrite) do
try
Position:=9;
while True do
begin
nBytes:=Read(buf[0],BUFFER_SIZE);
if nBytes=0 then Break;
for I:=0 to nBytes-1 do
buf:=buf shl 2;
Seek(-nBytes,soCurrent);
Write(buf[0],nBytes);
end;
finally
Free;
end;
end;