的TZipFile类的read方法可以用流
procedure Read(FileName: string; out Stream: TStream; out LocalHeader: TZipHeader); overload;
procedure Read(Index: Integer; out Stream: TStream; out LocalHeader: TZipHeader); overload;
从这里可以使用,你可以使用索引或访问文件名的压缩文件。
检查此示例使用TMemoryStream来保存未压缩的数据。
uses
Vcl.AxCtrls,
System.Zip;
procedure TForm41.Button1Click(Sender: TObject);
var
LStream : TStream;
LZipFile : TZipFile;
LOleGraphic: TOleGraphic;
LocalHeader: TZipHeader;
begin
LZipFile := TZipFile.Create;
try
//open the compressed file
LZipFile.Open('C:\Users\Dexter\Desktop\registry.zip', zmRead);
//create the memory stream
LStream := TMemoryStream.Create;
try
//LZipFile.Read(0, LStream, LocalHeader); you can use the index of the file
LZipFile.Read('SAM_0408.JPG', LStream, LocalHeader); //or use the filename
//do something with the memory stream
//now using the TOleGraphic to detect the image type from the stream
LOleGraphic := TOleGraphic.Create;
try
LStream.Position:=0;
//load the image from the memory stream
LOleGraphic.LoadFromStream(LStream);
//load the image into the TImage component
Image1.Picture.Assign(LOleGraphic);
finally
LOleGraphic.Free;
end;
finally
LStream.Free;
end;
finally
LZipFile.Free;
end;
end;
我正确的假设索引编制完成0,1,2,等每个增量是下一个文件吗?如果是这样,这比我想象的要容易得多。 – Larmos
是索引是从零开始的,并且最大值必须使用TZipFile类的'FileCount'属性获得。 – RRUZ
非常感谢。我明天会实施这个。 – Larmos