Writing and Reading Multipage Files (Access 95 and 97)

Take the following steps to create a multipage file, then load and display the images from the file. Only TIFF (MPT) and PCX (DCX) formats support multipage files.

1. Start with the project that you created in Loading and Displaying an Image.

2. In the Database window, select the Forms tab, select Form1, and click the Design button.

3. On the Insert pull-down menu, use the Custom Control option to select the Lead Control.

4. Click the OK button. The LEAD control appears on the form. (This is the second LEAD control.)

5. Drag the LEAD control to a convenient location on. The size and position does not really matter, because it is changed in the code.

6. In the properties box, change the name of the control to Lead2, and set its Visible property to False.

7. image\btncmd.gif Select the Command Button control; then add a control to your form. (Cancel the Command Button Wizard when it appears.) Put the control at the top of the form to keep it away from the images.

8. In the Properties box, change the Command Button control's Name property to Multipage and change the Caption property to Test Multipage.

9. Click the Code Window icon on the toolbar.

image\btncode.gif For Access 95.

image\btncode2.gif For Access 97.

10. Select the Click procedure for the Multipage object, and add the following code. In online help, you can select the block of code with the mouse, then press Ctrl-C to copy it.

' Declare some local variables
Dim HeightAllowed, WidthAllowed
Dim HeightFactor1, WidthFactor1, HeightFactor2, WidthFactor2
Dim ImageHeight1, ImageWidth1, ImageHeight2, ImageWidth2
Dim ImageLeft1, ImageTop1, ImageLeft2, ImageTop2

' Disable automatic repainting of the images.
Lead1.AutoRepaint = False
Lead2.AutoRepaint = False

' Turn off scroll bars to make sure we use the full client area.
Lead1.AutoScroll = False
Lead2.AutoScroll = False

' Hide the controls until we are ready to look at them.
Me![Lead1].Visible = False
Me![Lead2].Visible = False

' Display the form and set the mouse pointer to an hourglass.
DoCmd.Hourglass True

' Load the bitmaps. These hard-coded path names may be different on your system.
Lead1.Load "c:\lead\images\image1.cmp", 0, 0, 1
Lead2.Load "c:\lead\images\image2.cmp", 0, 0, 1

' Save the bitmaps to a single multipage TIFF file
Lead1.Save "c:\lead\images\combined.mpt", FILE_TIF, 24, 0, SAVE_OVERWRITE
Lead2.Save "c:\lead\images\combined.mpt", FILE_TIF, 24, 0, SAVE_APPEND

' Get information about the images so that we can size the controls.
Lead1.GetFileInfo "c:\lead\images\combined.mpt", 1, 0
Lead2.GetFileInfo "c:\lead\images\combined.mpt", 2, 0

' Clear the bitmaps from memory
Lead1.Bitmap = 0
Lead2.Bitmap = 0

' Make the controls visible so that we can size and position them.
Me![Lead1].Visible = True
Me![Lead2].Visible = True

'Set the variables used for preserving the aspect ratio.
HeightFactor1 = Lead1.InfoHeight
WidthFactor1 = Lead1.InfoWidth
HeightFactor2 = Lead2.InfoHeight
WidthFactor2 = Lead2.InfoWidth
HeightAllowed = Me.WindowHeight * 0.8
WidthAllowed = Me.WindowWidth * 0.45

'Center each LEAD control on half of the form, preserving the aspect ratio.
'Check to see if using the maximum width will make the image too tall.
'Set the dimensions based on the result.
If (WidthAllowed * HeightFactor1) / WidthFactor1 < HeightAllowed Then
  Me![Lead1].Left = (Me.WindowWidth / 4) - (WidthAllowed / 2)
  Me![Lead1].Width = WidthAllowed
  Me![Lead1].Height = (Me![Lead1].Width * HeightFactor1) / WidthFactor1
  Me![Lead1].Top = (Me.WindowHeight - Me![Lead1].Height) / 2
Else
  Me![Lead1].Top = (Me.WindowHeight - HeightAllowed) / 2
  Me![Lead1].Height = HeightAllowed
  Me![Lead1].Width = (Me![Lead1].Height * WidthFactor1) / HeightFactor1
  Me![Lead1].Left = (Me.WindowWidth / 4) - (Me![Lead1].Width / 2)
End If

If (WidthAllowed * HeightFactor2) / WidthFactor2 < HeightAllowed Then
  Me![Lead2].Left = (Me.WindowWidth * 3 / 4) - (WidthAllowed / 2)
  Me![Lead2].Width = WidthAllowed
  Me![Lead2].Height = (Me![Lead2].Width * HeightFactor2) / WidthFactor2
  Me![Lead2].Top = (Me.WindowHeight - Me![Lead2].Height) / 2
Else
  Me![Lead2].Top = (Me.WindowHeight - HeightAllowed) / 2
  Me![Lead2].Height = HeightAllowed
  Me![Lead2].Width = (Me![Lead2].Height * WidthFactor2) / HeightFactor2
  Me![Lead2].Left = (Me.WindowWidth * 3 / 4) - (Me![Lead2].Width / 2)
End If

' Load the bitmaps from the multipage TIFF file
Lead1.Load "c:\lead\images\combined.mpt", 24, 1, 1
Lead2.Load "c:\lead\images\combined.mpt", 24, 2, 1

' Set the image display sizes to match the LEAD controls
ImageHeight1 = Lead1.ScaleHeight
ImageWidth1 = Lead1.ScaleWidth
Lead1.SetDstRect 0, 0, ImageWidth1, ImageHeight1
Lead1.SetDstClipRect 0, 0, ImageWidth1, ImageHeight1
ImageHeight2 = Lead2.ScaleHeight
ImageWidth2 = Lead2.ScaleWidth
Lead2.SetDstRect ImageLeft2, ImageTop2, ImageWidth2, ImageHeight2
Lead2.SetDstClipRect ImageLeft2, ImageTop2, ImageWidth2, ImageHeight2

' Display the images
Lead1.ForceRepaint
Lead2.ForceRepaint

'Set the mouse pointer back to the default
DoCmd.Hourglass False

11. image\btncmpl.gif Click the compile button on the toolbar; then close the code window.

12. Close the form designer, saving the changes.

13. With Form1 selected in the Database window, click the Open button to test the form. Notice that the text printed on the bitmap is scaled as part of the bitmap. If you zoom in, it becomes larger, and if you zoom out, it becomes smaller. The text printed on the control is the normal size for the system font and is not affected by zooming.