C
colonel
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TForm1.Button1Click(Sender: TObject);<br>var<br> PicStream: OleVariant;<br> vStream: TFileStream;<br> vStreamA: TMemoryStream;<br>begin<br> if OpenDialog1.Execute then<br> begin<br> vStream:= TFileStream.Create(OpenDialog1.FileName, fmOpenRead);<br> vStreamA:= TMemoryStream.Create;<br> try<br> Image1.Picture.Bitmap.LoadFromStream(vStream);<br> PicStream:= StreamToVariant(vStream);<br><br> VariantToStream(PicStream, vStreamA);<br> Image2.Picture.Bitmap.LoadFromStream(vStreamA);<br> finally<br> freeandnil(vStream);<br> freeandnil(vStreamA);<br> end;<br> end;<br>end;<br>//------------------------------------<br>procedure VariantToStream(const Data: OleVariant; Stream: TStream);<br>var <br> p: Pointer; <br>begin <br> p := VarArrayLock(Data);<br> try <br> Stream.Write(p^, VarArrayHighBound(Data,1) + 1); <br> finally <br> VarArrayUnlock(Data);<br> end; <br>end; <br><br>function StreamToVariant(Stream: TStream): OleVariant;<br>var <br> p: Pointer; <br>begin <br> Result := VarArrayCreate([0, Stream.Size - 1], varByte); <br> p := VarArrayLock(Result); <br> try <br> Stream.Position := 0; <br> Stream.Read(p^, Stream.Size); <br> finally <br> VarArrayUnlock(Result); <br> end; <br>end;