Autor Beitrag
MrFox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 208

WIN 2000 Professional, Ubuntu 5.10
D3 Prof, D7 Pers, D2005 Pers, Java (Eclipse)
BeitragVerfasst: Fr 03.03.06 15:00 
user profile iconJailbird hat folgendes geschrieben:
Bei der Decompression ist's genau umgekehrt...ich schreib mal pseudomässig, wie's funzt.

Lade komp. Datei in TFileStream (z.B.)
Create den TDecompressionStream mit dem FileStream als Attribut
Wähle Bitmap.LoadFromStream(decStream)
Free


Hehe, wenns doch so einfach wäre. :D

LoadFromStream(CompressionStream) löst ebenfalls eine Invalid Stream Operation - Exception aus.

_________________
Das Leben auf der Erde mag zwar teuer sein, aber eine jährliche Rundreise um die Sonne ist gratis mit dabei.
Jailbird
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 127

Windows XP Pro SP2
Delphi 7 Professional
BeitragVerfasst: Fr 03.03.06 15:29 
hier musste wohl oder übel über den memorystream

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
var
  Bitmap: TBitmap;
  FStream: TFileStream;
  DStream: TDecompressionStream;
  MStream: TMemoryStream;
  Buffer: Array[0..32767] of Byte;
  NumBytes: Integer;
begin
  FStream := TFileStream.Create('datei_komprimiert.bmp', fmOpenRead);
  Bitmap := TBitmap.Create;
  MStream := TMemoryStream.Create;
  DStream := TDecompressionStream.Create(FStream);

  repeat
    NumBytes := DStream.Read(Buffer, SizeOf(Buffer));
    if NumBytes > 0 then MStream.Write(Buffer, NumBytes);
  until NumBytes <> SizeOf(Buffer);
  MStream.Seek(0, soFromBeginning);
  Bitmap.LoadFromStream(MStream);
  Canvas.Draw(0, 0, Bitmap);

  DStream.Free;
  MStream.Free;
  Bitmap.Free;
  FStream.Free;
end;
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Fr 03.03.06 15:54 
@ Benbe: Hmmm, stimmt. Die Implementation von LoadFromStream in TBitmap ist einfach grauenhaft:

ausblenden Delphi-Quelltext
1:
 ReadStream(Stream, Stream.Size - Stream.Position);					


Sprich: "Alles im Stream ab der aktuellen Position ist ja wohl Bitmap". :?

Da TDecompressionStream den Abruf von Size nicht erlaubt, kommt natürlich eine Exception. Deshalb also der Umweg über den MemoryStream nehmen.

Cu,
Udontknow