PaintPalette example for Access 2.0

This example sets the paint palette to the palette of each Lead control. It then loads two images and dithers them to 8 bits per pixel with optimized palettes, and displays them side by side. In 8-bit display mode, you can see the palette problems that result when you do not use a fixed palette.

Me![LEAD1].Object.PaintPalette = PAINTPALETTE_AUTO
Me![LEAD2].Object.PaintPalette = PAINTPALETTE_AUTO

'Disable automatic repainting of the image.
Me![LEAD1].Object.AutoRepaint = False
Me![LEAD2].Object.AutoRepaint = False

'Turn off scroll bars to make sure we use the full client area.
Me![LEAD1].Object.AutoScroll = False
Me![LEAD2].Object.AutoScroll = False

'Clear the bitmaps from memory
Me![LEAD1].Object.Bitmap = 0
Me![LEAD2].Object.Bitmap = 0

DoCmd Hourglass True
'Load the bitmaps. These hard-coded path names may be different on your system.
Me![LEAD1].Object.Load "c:\lead\images\image1.cmp", 0, 0, 1
Me![LEAD2].Object.Load "c:\lead\images\image2.cmp", 0, 0, 1

'Change the bitmaps to 8 BPS with optimized palettes
Me![LEAD1].Object.ColorRes 8, CRP_OPTIMIZEDPALETTE, CRD_FLOYDSTEINDITHERING, 0
Me![LEAD2].Object.ColorRes 8, CRP_OPTIMIZEDPALETTE, CRD_FLOYDSTEINDITHERING, 0

'Make the controls visible so that we can size and position them.
'They will not really appear until we load an image and paint it.
Me![LEAD1].Visible = True
Me![LEAD2].Visible = True

'Set the variables used for preserving the aspect ratio.
HeightFactor1 = Me![LEAD1].Object.BitmapHeight
WidthFactor1 = Me![LEAD1].Object.BitmapWidth
HeightFactor2 = Me![LEAD2].Object.BitmapHeight
WidthFactor2 = Me![LEAD2].Object.BitmapWidth
HeightAllowed = Me.WindowHeight * .8
WidthAllowed = Me.WindowWidth * .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

'Set the image display sizes to match the LEAD controls
ImageHeight1 = Me![LEAD1].Object.ScaleHeight 
ImageWidth1 = Me![LEAD1].Object.ScaleWidth 
Me![LEAD1].Object.SetDstRect 0, 0, ImageWidth1, ImageHeight1
Me![LEAD1].Object.SetDstClipRect 0, 0, ImageWidth1, ImageHeight1

'Set the image display sizes to match the LEAD controls
ImageHeight2 = Me![LEAD2].Object.ScaleHeight 
ImageWidth2 = Me![LEAD2].Object.ScaleWidth 
Me![LEAD2].Object.SetDstRect ImageLeft2, ImageTop2, ImageWidth2, ImageHeight2
Me![LEAD2].Object.SetDstClipRect ImageLeft2, ImageTop2, ImageWidth2, ImageHeight2

'Display the images
Me![LEAD1].Object.ForceRepaint
Me![LEAD2].Object.ForceRepaint
DoCmd Hourglass False