???????????无法理解代码意识?????????(50分)

  • 主题发起人 主题发起人 zhbj
  • 开始时间 开始时间
Z

zhbj

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure CompressIt(var CompressedStream: TMemoryStream; const CompressionLevel: TCompressionLevel);
// 参数是传递的流和压缩方式
var
SourceStream: TCompressionStream;
DestStream: TMemoryStream;
Count: int64; //注意,此处修改了,原来是int
begin
Count := CompressedStream.Size;//获得流的原始尺寸
DestStream := TMemoryStream.Create;
SourceStream := TCompressionStream.Create(CompressionLevel, DestStream);
try
CompressedStream.SaveToStream(SourceStream);//SourceStream中保存着原始的流
SourceStream.Free;//将原始流进行压缩,DestStream中保存着压缩后的流
CompressedStream.Clear;
CompressedStream.WriteBuffer(Count, SizeOf(Count));//写入原始图像的尺寸
CompressedStream.CopyFrom(DestStream, 0);//写入经过压缩的流
finally
DestStream.Free;
end;
end;
 
我也看不懂。
 
没用过Zlib。
但是看上去还是可以理解的。下面是我看代码所进行的理解。
procedure CompressIt(var CompressedStream: TMemoryStream;
const CompressionLevel: TCompressionLevel);
var
SourceStream: TCompressionStream; //SourceStream是负责压缩的流
DestStream: TMemoryStream; //DestStream保存的是压缩后的流
Count: int64;
begin
Count := CompressedStream.Size;
DestStream := TMemoryStream.Create;
SourceStream := TCompressionStream.Create(CompressionLevel, DestStream);
//根据压缩级别创建SourceStream,输出流为DestStream
try
CompressedStream.SaveToStream(SourceStream);//SourceStream会把压缩后的流输出到DestStream
SourceStream.Free;//SourceStream已经不需要了
CompressedStream.Clear;
CompressedStream.WriteBuffer(Count, SizeOf(Count));//写入原始图像的尺寸
CompressedStream.CopyFrom(DestStream, 0);//写入经过压缩的流
finally
DestStream.Free;
end;
end;
 
TCompressionStream应该是自己定义的类,看去看来就这句有点用
SourceStream := TCompressionStream.Create(CompressionLevel, DestStream);
看看 TCompressionStream的构造函数是怎么写的吧。
 
shenloqi你太逗了 :

我是说
CompressedStream是否和SourceStream 重复?
为什么要
SourceStream := TCompressionStream.Create(CompressionLevel, DestStream);
为什么要
CompressedStream.SaveToStream(SourceStream) ;
句子 CompressedStream.WriteBuffer(Count, SizeOf(Count));
中的 Count不应该是DestStream.size吗?
……
 
每人理了吗???
 
多人接受答案了。
 
后退
顶部