unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls,jpeg;
type
TForm1 =
class(TForm)
Memo1: TMemo;
Image1: TImage;
Memo2: TMemo;
Image2: TImage;
Button2: TButton;
Button3: TButton;
procedure Zusammenfügen();
procedure Trennen ();
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
{ TForm1 }
procedure TForm1.Button2Click(Sender: TObject);
begin
zusammenfügen();
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
trennen();
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
image1.picture.loadfromfile('
./bild.jpg');
end;
procedure TForm1.Trennen;
var
lStream: TStream;
lStartPos: Int64;
lDataSize: Cardinal;
TextStream, JPEGStream: TMemoryStream;
bildchen: tjpegimage;
begin
lStream := TFileStream.Create('
./meinStream.ampstr', fmOpenRead);
try
// Länge lesen
lStream.
Read(lDataSize, sizeOf(lDataSize));
TextStream := TMemoryStream.Create;
TextStream.Size := lDataSize;
// Text auslesen
TextStream.copyfrom(lStream, lDataSize);
memo2.Lines.LoadFromStream(TextStream);
TextStream.Free;
// Bild laden
lStream.Position := sizeof(lDataSize) + lDataSize;
// Diese Zeile sollte weggelassen werden können, da der Stream ja schon die richtige Position hat.
// Länge lesen
lStream.
Read(lDataSize, sizeOf(lDataSize));
JPEGStream := TMemoryStream.Create;
JPEGStream.Size := lDataSize;
// Text auslesen
JPEGStream.copyfrom(lStream, lDataSize);
bildchen:= tjpegimage.Create;
bildchen.LoadFromStream(JPEGStream);
bildchen.SaveToFile('
./bildnew.jpg');
JPEGStream.Free;
bildchen.Free;
finally
lStream.Free;
end;
end;
procedure TForm1.Zusammenfügen;
var
lStream: TStream;
lStartPos: Int64;
lDataSize: Cardinal;
bildchen:tjpegimage;
begin
lStream := TFileStream.Create('
./meinStream.ampstr', fmCreate);
try
// Memo speichern
lStartPos := 0;
lStream.Position := lStream.Position + sizeof(lDataSize);
memo1.Lines.SaveToStream(lStream);
lDataSize := lStream.Position - lStartPos - sizeof(lDataSize);
lStream.Position := lStartPos;
lStream.
Write(lDataSize, sizeof(lDataSize));
// JPG speichern
lStartPos := lStream.Size;
lStream.Position := lStream.Position + sizeof(lDataSize);
bildchen:= tjpegimage.Create;
bildchen.LoadFromFile('
./bild.jpg');
bildchen.SaveToStream(lstream);
lDataSize := lStream.Position - lStartPos - sizeof(lDataSize);
lStream.Position := lStartPos;
lStream.
Write(lDataSize, sizeof(lDataSize));
finally
lStream.Free;
bildchen.Free;
end;
end;
end.