Variable image sizes (jpg, gif and bmp) in a Crystal Report
Posted on 2003-03-26
Using VB 6 and Crystal Reports 8.5, I'm trying to produce a report that includes photos relating to the file summary I am generating. Each report can have any number of photos included, and the images can be either BMP, JPG or GIFs. The filepath and filename for each photo is pulled from the database at runtime.
By creating the report with a dummy photo and then using LoadPicture to replace it with the correct photo, I've had no problems loading each image. My problem is that each photo is compressed or expanded to fit the dimensions of the initial dummy photo. I need to be able to resize each photo to its original dimensions. I know how to handle the resizing, but can't figure out how to determine the images' real dimensions at runtime. I've seen one function to determine bitmap dimensions using header information, but need something to handle JPG and GIF files as well.
Code so far (in the Report Designer):
Private Sub Photos_Format(ByVal pFormattingInfo As Object)
Dim iPhotoWidth As Integer
Dim iPhotoHeight As Integer
' sPhotoPath is a variable for the filepath that is set when initializing the report.
' PhotoFileName is a suppressed field containing the filename of the photo (e.g. 137.jpg)
Set Photo.FormattedPicture = LoadPicture(sPhotoPath & PhotoFileName.Value)
' Determine photo dimensions
iPhotoWidth = ??? ' need function
iPhotoHeight = ??? ' need function
' Resize photo
Photo.Width = iPhotoWidth
Photo.Height = iPhotoHeight