views:

289

answers:

3

Hi

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 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# ??

Please help.

-Tim

+1  A: 

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 (e.g. SharpZipLib) supporting .Net within your C# code.

Peter Lillevold
Yeah, it seems TDecompressionStream uses ZLIB compression, so you'll need to go with a third-party library such as SharpZipLip (there are others too, but that seems to be the best).
Noldorin
+3  A: 

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

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

-Oisin

x0n
Thanks, I just tried this and it works a treat :-)
Cool, glad I could help.
x0n
A: 

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.

Bruce McGee