I have been unable to get PictureStream to work properly. (VCL Ver 7.00 with XE5)
By way of an example in the code below, I am attempting to open a JPG file, copy it to a TVPEStream and then insert it into a doc using PictureStream. (In practise, I'm wanting to use a database BlobStream as the source rather than a file.)
RESULT: I get LastError = VERR_PIC_IMPORT after attempting to output the image with PictureStream.
As indicated in the code, if I use "Picture" to print the image directly from the source file, I have no problem (so I assume there is nothing wrong with the JPG image as such).
A check of AFileStream and AVPEStream indicates that both have the same size (32404 in this case) so there is no apparent data loss.
Thanks.
- Code: Select all
- procedure TForm1.Button1Click(Sender: TObject);
 var
 AFileStream: TFileStream;
 Buffer: TBytes;
 BytesToRead: Integer;
 BufSize, ACount: Integer;
 AVPEStream: TVPEStream;
 begin
 with VPEngine1 do
 begin
 OpenDoc;
 AVPEStream := CreateMemoryStream(16000);
 //stream from file
 AFileStream := TFileStream.Create('E:\Temp\MyImage.jpg', fmOpenRead);
 try
 //copy to VPEStream
 BytesToRead := AFileStream.Size;
 AFileStream.Position := 0;
 BufSize := 16000;
 SetLength(Buffer, BufSize);
 try
 while (BytesToRead > 0) do
 begin
 if (BytesToRead > BufSize) then
 ACount := BufSize
 else
 ACount := BytesToRead;
 AFileStream.ReadBuffer(Buffer, ACount);
 AVPEStream.Write(Buffer, ACount);
 Dec(BytesToRead, ACount);
 end;
 finally
 SetLength(Buffer, 0);
 end;
 finally
 AFileStream.Free;
 end;
 AVPEStream.Seek(0);
 //print picture stream
 PictureBestFit := True;
 PictureKeepAspect := True;
 //this fails with LastError = VERR_PIC_IMPORT (300)
 PictureStream(AVPEStream, 2, 2, 12, VFREE, 'test');
 ShowMessageFmt('LastError = %d', [LastError]);
 //using the image file directly succeeds
 //Picture(2, 2, 12, VFREE, 'E:\Temp\MyImage.jpg');
 AVPEStream.Free;
 Preview;
 end;
 end;

