Code
procedure StreamToVariant(Stream: TMemoryStream;
var v: OleVariant);
procedure VariantToStream(const v: olevariant;
Stream: TMemoryStream);
procedure JPEGToVariant(aJPEG : TJPEGImage;
var aVariant:OleVariant);
procedure VariantToJPEG(aValue : OleVariant;
var aJPEG:TJPEGImage);
procedure TForm1.VariantToStream (const v : olevariant; Stream : TMemoryStream);
var
p : pointer;
begin
Stream.Position := 0;
Stream.Size := VarArrayHighBound (v, 1) - VarArrayLowBound (v, 1) + 1;
p := VarArrayLock (v);
Stream.Write (p^, Stream.Size);
VarArrayUnlock (v);
Stream.Position := 0;
end;
procedure TForm1.StreamToVariant (Stream : TMemoryStream; var v : OleVariant);
var
p : pointer;
begin
v := VarArrayCreate ([0, Stream.Size - 1], varByte);
p := VarArrayLock (v);
Stream.Position := 0;
Stream.Read (p^, Stream.Size);
VarArrayUnlock (v);
end;
procedure TForm1.JPEGToVariant(aJPEG : TJPEGImage; var aVariant:OleVariant);
var
Stream : TMemoryStream;
begin
try
Stream := TMemoryStream.Create;
aJPEG.Assign(Image1.Picture.Bitmap);
aJPEG.SaveToStream(Stream);
StreamToVariant(Stream, aVariant);
finally
Stream.Free;
end;
end;
procedure TForm1.VariantToJPEG(aValue : OleVariant;var aJPEG:TJPEGImage);
var
Stream : TMemoryStream;
begin
try
Stream := TMemoryStream.Create;
VariantToStream (aValue,Stream);
aJPEG.LoadfromStream(Stream);
finally
VariantClear(aValue);
Stream.free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
aJPEG :TJPEGImage;
aVariant : OleVariant;
begin
try
aJPEG:=TJPEGImage.Create;
//JPEG To Variant
aJPEG.Assign(Image1.Picture.Bitmap);
JPEGToVariant(aJPEG,aVariant);
//Variant To JPEG
VariantToJPEG(aVariant,aJPEG);
Image2.Picture.assign(aJPEG);
finally
aJPEG.free;
end;
end;
procedure StreamToVariant(Stream: TMemoryStream;
var v: OleVariant);
procedure VariantToStream(const v: olevariant;
Stream: TMemoryStream);
procedure JPEGToVariant(aJPEG : TJPEGImage;
var aVariant:OleVariant);
procedure VariantToJPEG(aValue : OleVariant;
var aJPEG:TJPEGImage);
procedure TForm1.VariantToStream (const v : olevariant; Stream : TMemoryStream);
var
p : pointer;
begin
Stream.Position := 0;
Stream.Size := VarArrayHighBound (v, 1) - VarArrayLowBound (v, 1) + 1;
p := VarArrayLock (v);
Stream.Write (p^, Stream.Size);
VarArrayUnlock (v);
Stream.Position := 0;
end;
procedure TForm1.StreamToVariant (Stream : TMemoryStream; var v : OleVariant);
var
p : pointer;
begin
v := VarArrayCreate ([0, Stream.Size - 1], varByte);
p := VarArrayLock (v);
Stream.Position := 0;
Stream.Read (p^, Stream.Size);
VarArrayUnlock (v);
end;
procedure TForm1.JPEGToVariant(aJPEG : TJPEGImage; var aVariant:OleVariant);
var
Stream : TMemoryStream;
begin
try
Stream := TMemoryStream.Create;
aJPEG.Assign(Image1.Picture.Bitmap);
aJPEG.SaveToStream(Stream);
StreamToVariant(Stream, aVariant);
finally
Stream.Free;
end;
end;
procedure TForm1.VariantToJPEG(aValue : OleVariant;var aJPEG:TJPEGImage);
var
Stream : TMemoryStream;
begin
try
Stream := TMemoryStream.Create;
VariantToStream (aValue,Stream);
aJPEG.LoadfromStream(Stream);
finally
VariantClear(aValue);
Stream.free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
aJPEG :TJPEGImage;
aVariant : OleVariant;
begin
try
aJPEG:=TJPEGImage.Create;
//JPEG To Variant
aJPEG.Assign(Image1.Picture.Bitmap);
JPEGToVariant(aJPEG,aVariant);
//Variant To JPEG
VariantToJPEG(aVariant,aJPEG);
Image2.Picture.assign(aJPEG);
finally
aJPEG.free;
end;
end;