PaintPalette example for Visual Basic
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.
Dim HeightFactor1
Dim WidthFactor1
Dim HeightFactor2
Dim WidthFactor2
Dim HeightAllowed
Dim WidthAllowed
Dim RasterIO As New LEADRasterIO
Dim RasterProc As New LEADRasterProcess
LEADRasterView1.PaintPalette = PAINTPALETTE_AUTO
LEADRasterView2.PaintPalette = PAINTPALETTE_AUTO
'Disable automatic repainting of the image.
LEADRasterView1.AutoRepaint = False
LEADRasterView2.AutoRepaint = False
'Turn off scroll bars to make sure we use the full client area.
LEADRasterView1.AutoScroll = False
LEADRasterView2.AutoScroll = False
'Clear the bitmaps from memory
LEADRasterView1.Raster.Bitmap = 0
LEADRasterView2.Raster.Bitmap = 0
Screen.MousePointer = 11 'Hourglass
'Load the bitmaps. These hard-coded path names may be different on your system.
RasterIO.Load LEADRasterView1.Raster, "d:\temp\24bit.bmp", 0, 0, 1
RasterIO.Load LEADRasterView2.Raster, "d:\temp\24bit2.bmp", 0, 0, 1
'Change the bitmaps to 8 BPS with optimized palettes
RasterProc.ColorRes LEADRasterView1.Raster, 8, CRP_OPTIMIZEDPALETTE, CRD_FLOYDSTEINDITHERING, 0
RasterProc.ColorRes LEADRasterView2.Raster, 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.
LEADRasterView1.Visible = True
LEADRasterView2.Visible = True
'Set the variables used for preserving the aspect ratio.
HeightFactor1 = LEADRasterView1.Raster.BitmapHeight
WidthFactor1 = LEADRasterView1.Raster.BitmapWidth
HeightFactor2 = LEADRasterView2.Raster.BitmapHeight
WidthFactor2 = LEADRasterView2.Raster.BitmapWidth
HeightAllowed = ScaleHeight * 0.8
WidthAllowed = ScaleWidth * 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
LEADRasterView1.Left = (ScaleWidth / 4) - (WidthAllowed / 2)
LEADRasterView1.Width = WidthAllowed
LEADRasterView1.Height = (LEADRasterView1.Width * HeightFactor1) / WidthFactor1
LEADRasterView1.Top = (ScaleHeight - LEADRasterView1.Height) / 2
Else
LEADRasterView1.Top = (ScaleHeight - HeightAllowed) / 2
LEADRasterView1.Height = HeightAllowed
LEADRasterView1.Width = (LEADRasterView1.Height * WidthFactor1) / HeightFactor1
LEADRasterView1.Left = (ScaleWidth / 4) - (LEADRasterView1.Width / 2)
End If
If (WidthAllowed * HeightFactor2) / WidthFactor2 < HeightAllowed Then
LEADRasterView2.Left = (ScaleWidth * 3 / 4) - (WidthAllowed / 2)
LEADRasterView2.Width = WidthAllowed
LEADRasterView2.Height = (LEADRasterView2.Width * HeightFactor2) / WidthFactor2
LEADRasterView2.Top = (ScaleHeight - LEADRasterView2.Height) / 2
Else
LEADRasterView2.Top = (ScaleHeight - HeightAllowed) / 2
LEADRasterView2.Height = HeightAllowed
LEADRasterView2.Width = (LEADRasterView2.Height * WidthFactor2) / HeightFactor2
LEADRasterView2.Left = (ScaleWidth * 3 / 4) - (LEADRasterView2.Width / 2)
End If
'Set the image display sizes to match the LEAD controls
LEADRasterView1.SetDstRect 0, 0, LEADRasterView1.ScaleWidth, LEADRasterView1.ScaleHeight
LEADRasterView1.SetDstClipRect 0, 0, LEADRasterView1.ScaleWidth, LEADRasterView1.ScaleHeight
LEADRasterView2.SetDstRect 0, 0, LEADRasterView2.ScaleWidth, LEADRasterView2.ScaleHeight
LEADRasterView2.SetDstClipRect 0, 0, LEADRasterView2.ScaleWidth, LEADRasterView2.ScaleHeight
'Display the images
LEADRasterView1.ForceRepaint
LEADRasterView2.ForceRepaint
Screen.MousePointer = 0 ' Default