简体   繁体   中英

What's the C# Equivalent of a Delphi TDecompressionStream?

I have some Delphi code that did this needs to be re-coded in C#:

procedure TDocSearchX.Decompress;
var
BlobStream:TBlobStream;
DecompressionStream:TDecompressionStream;
FileStream:TFileStream;
Buffer:array[0..2047] of byte;
count:integer;
begin
    BlobStream:=TBlobStream.Create(DocQueryDATA,bmRead);
    DecompressionStream:=TDecompressionStream.Create(BlobStream);
    FileStream:=TFileStream.Create(FDocFile,fmCreate);
    while True do
    begin
        Count := DecompressionStream.Read(Buffer, 2048);
        if Count <> 0 then FileStream.Write(Buffer, Count) else Break;
    end;
    Blobstream.Free;
    DecompressionStream.Free;
    FileStream.Free;
end;

The contractor that wrote this is leaving and I need to decompress the image (that is currently stored in the database). I have been able to extract the image to a file but have no idea how to decompress it using C#?

It looks like TDecompressionStream probably uses ZLib. Here is a .NET library for ZLIB:

http://www.componentace.com/zlib_.NET.htm

To my knowledge there is no .Net Framework equivalent to the TDecompressionStream class. Are you able to write a small converter app in Delphi that decompresses the image? Then you are free to use whatever compression library (eg SharpZipLib) supporting .Net within your C# code.

If you have to keep the same compression already used, roll the Delphi decompression routine into a DLL and use it from C# using PInvoke.

If you want to replace the compression, write a batch process to extract the Delphi compressed images, decompress them to their original format and re-compress them with your favourite C# library.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM