Example of PictureStream request

Knowledge exchange related to the VPE Report Engine and PDF Library

Moderator: IDEAL Software Support

Example of PictureStream request

Postby EvP » Wed Nov 17, 2010 11:53 am

Hi, i'm trying to put a picture from a database into a report using PictureStream.

I went through the reference manual but I can't get it to work, and the manual is pretty unclear to me about this.

I'm using Delphi and VPE Professional version 6

I came this far, no clue if i'm barking up the wrong tree or that's it's just a minor problem.

(this is not the actual code, it's just an example i tried to create)

Can you help me out ?


Procedure ImagePrint;

var

Blob : Tstream;
PictureStream : VPEStream;
VertPos : Double; // vertical position
Buffer : Tbytes;


begin
VertPos := 0.5;

Report.OpenDoc;
Report.License('VPE-xxxxx-xxxx', 'xxxx-xxxx'); // enable license

PictureStream := Report.CreateMemoryStream(64000); // picture should fit in 64k

Data.dbImage.First; // go to first record of database
while not Data.dbImage.Eof do // until end reached
begin
// fill the blob with the Picture;
Blob := Data.dbImage.CreateBlobStream(Data.dbImage.FieldByName('PICTURE'), bmread);

// ... problem code starts here

SetLength(Buffer, Blob.Size);
Blob.Read(Buffer, Blob.size);
PictureStream.Write(Buffer,Blob.Size);

// ... problem code ends here

// Put the picture in the document and give it the ID of the picture
Report.PictureStream(PictureStream,1,VertPos,6,VertPos+5,data.dbImage.FieldValues['CATID']);

VertPos := VerPos + 6;

end;

Report.Preview;


end;



Kind regards, Erik van Putten
EvP
 
Posts: 4
Joined: Sat Oct 10, 2009 6:02 pm

Re: Example of PictureStream request

Postby IDEAL Software Support » Thu Nov 18, 2010 7:41 am

You should check the property LastError after calling the VPE API in order to find out where the problem is.

From a rough view at your code, it seems there is a call to Seek(0) missing:

Code: Select all
PictureStream.Write(Buffer,Blob.Size);
==>PictureStream.Seek(0)


After you have written the blob to the VPE memory stream, the internal file pointer of the VPE memory stream needs to be reset to the beginning, because the following call to PictureStream() will read from the current stream position. There is sample source code for Delphi shipped with VPE, where this is demonstrated.
IDEAL Software Support
 
Posts: 1633
Joined: Thu Nov 18, 2004 4:03 pm


Return to VPE Open Forum

Who is online

Users browsing this forum: No registered users and 17 guests

cron