Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
PaintOverlay(Graphics,Int32,Rectangle,Rectangle,Rectangle,Rectangle,RasterPaintProperties) Method
See Also  Example
Leadtools Namespace > RasterImage Class > PaintOverlay Method : PaintOverlay(Graphics,Int32,Rectangle,Rectangle,Rectangle,Rectangle,RasterPaintProperties) Method



graphics
The destination graphics object where the image will be displayed.
index
The index of the overlay used for painting. The overlay should have an image. If the overlay is embedded into an image bitplane, make sure you create an overlay image prior to calling this method. This index is zero-based.
srcRect
Rectangle which determines the portion of the image to paint.
srcClipRect
Rectangle which further clips the source image.
destRect
Rectangle which determines where the image is placed, and how it is scaled.
destClipRect
Rectangle which clips the image display.
properties
Options for the display.
Paints the overlay at the specified index. Use this method to paint overlays that are not automatically painted.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub PaintOverlay( _
   ByVal graphics As Graphics, _
   ByVal index As Integer, _
   ByVal srcRect As Rectangle, _
   ByVal srcClipRect As Rectangle, _
   ByVal destRect As Rectangle, _
   ByVal destClipRect As Rectangle, _
   ByVal properties As RasterPaintProperties _
) 
Visual Basic (Usage)Copy Code
Dim instance As RasterImage
Dim graphics As Graphics
Dim index As Integer
Dim srcRect As Rectangle
Dim srcClipRect As Rectangle
Dim destRect As Rectangle
Dim destClipRect As Rectangle
Dim properties As RasterPaintProperties
 
instance.PaintOverlay(graphics, index, srcRect, srcClipRect, destRect, destClipRect, properties)
C# 
public void PaintOverlay( 
   Graphics graphics,
   int index,
   Rectangle srcRect,
   Rectangle srcClipRect,
   Rectangle destRect,
   Rectangle destClipRect,
   RasterPaintProperties properties
)
C++/CLI 
public:
void PaintOverlay( 
   Graphics graphics,
   int index,
   Rectangle srcRect,
   Rectangle srcClipRect,
   Rectangle destRect,
   Rectangle destClipRect,
   RasterPaintProperties properties
) 

Parameters

graphics
The destination graphics object where the image will be displayed.
index
The index of the overlay used for painting. The overlay should have an image. If the overlay is embedded into an image bitplane, make sure you create an overlay image prior to calling this method. This index is zero-based.
srcRect
Rectangle which determines the portion of the image to paint.
srcClipRect
Rectangle which further clips the source image.
destRect
Rectangle which determines where the image is placed, and how it is scaled.
destClipRect
Rectangle which clips the image display.
properties
Options for the display.

Example

Visual BasicCopy Code
Public Sub PaintOverlayExample()
   Dim f As PaintOverlayForm = New PaintOverlayForm()
   f.ShowDialog()
End Sub

Private Class PaintOverlayForm : Inherits Form
   Private image As RasterImage
   Private props As RasterPaintProperties

   Public Sub New()
      ' Load the image
      RasterCodecs.Startup()
      Dim codecs As RasterCodecs = New RasterCodecs()

      image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE2.DIC")
      Dim overlay As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "OCR1.TIF")
      Dim cmd As ResizeCommand = New ResizeCommand()
      Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height, 1, RasterByteOrder.Bgr, image.ViewPerspective, Nothing, IntPtr.Zero, 0)
      cmd.Flags = RasterSizeFlags.FavorBlack
      cmd.DestinationImage = destImage
      cmd.Run(overlay)
      image.SetOverlayImage(0, destImage, RasterGetSetOverlayImageMode.Copy)
      destImage.Dispose()
      overlay.Dispose()

      Dim attributes As RasterOverlayAttributes = image.GetOverlayAttributes(0, RasterGetSetOverlayAttributesFlags.Color Or RasterGetSetOverlayAttributesFlags.Flags Or RasterGetSetOverlayAttributesFlags.Origin Or RasterGetSetOverlayAttributesFlags.BitIndex)

      attributes.AutoPaint = False
      attributes.Color = New RasterColor(255, 0, 0)

      image.UpdateOverlayAttributes(0, attributes, RasterGetSetOverlayAttributesFlags.Color Or RasterGetSetOverlayAttributesFlags.Flags Or RasterGetSetOverlayAttributesFlags.Origin Or RasterGetSetOverlayAttributesFlags.BitIndex)

      Text = "PaintOverlay Example"
      props = RasterPaintProperties.Default
      props.UsePaintPalette = True
   End Sub

   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
      ' Clean up
      If disposing Then
         image.Dispose()
         RasterCodecs.Shutdown()
      End If

      MyBase.Dispose(disposing)
   End Sub

   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
      ' Draw the image fit and center on this form
      Dim destRect As Rectangle = RasterImage.CalculatePaintModeRectangle(image.ImageWidth, image.ImageHeight, ClientRectangle, RasterPaintSizeMode.Fit, RasterPaintAlignMode.Center, RasterPaintAlignMode.Center)
      image.Paint(e.Graphics, Rectangle.Empty, destRect, props)
      image.PaintOverlay(e.Graphics, 0, Rectangle.Empty, Rectangle.Empty, destRect, Rectangle.Empty, props)

      MyBase.OnPaint(e)
   End Sub
End Class
C#Copy Code
public void PaintOverlayExample() 

   PaintOverlayForm f = new PaintOverlayForm(); 
   f.ShowDialog(); 

 
class PaintOverlayForm : Form 

   RasterImage image; 
   RasterPaintProperties props; 
 
   public PaintOverlayForm() 
   { 
      // Load the image 
      RasterCodecs.Startup(); 
      RasterCodecs codecs = new RasterCodecs(); 
 
      image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE2.DCM"); 
      RasterImage overlay = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "OCR1.TIF"); 
      ResizeCommand cmd = new ResizeCommand(); 
      RasterImage destImage = new RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height, 1, RasterByteOrder.Bgr, image.ViewPerspective, null, IntPtr.Zero, 0); 
      cmd.Flags = RasterSizeFlags.FavorBlack; 
      cmd.DestinationImage = destImage; 
      cmd.Run(overlay); 
      image.SetOverlayImage(0, destImage, RasterGetSetOverlayImageMode.Copy); 
      destImage.Dispose(); 
      overlay.Dispose(); 
 
      RasterOverlayAttributes attributes = image.GetOverlayAttributes(0, 
         RasterGetSetOverlayAttributesFlags.Color | 
         RasterGetSetOverlayAttributesFlags.Flags | 
         RasterGetSetOverlayAttributesFlags.Origin | 
         RasterGetSetOverlayAttributesFlags.BitIndex); 
 
      attributes.AutoPaint = false; 
      attributes.Color = new RasterColor(255, 0, 0); 
 
      image.UpdateOverlayAttributes( 
         0, 
         attributes, 
         RasterGetSetOverlayAttributesFlags.Color | 
         RasterGetSetOverlayAttributesFlags.Flags | 
         RasterGetSetOverlayAttributesFlags.Origin | 
         RasterGetSetOverlayAttributesFlags.BitIndex); 
 
      Text = "PaintOverlay Example"; 
      props = RasterPaintProperties.Default; 
      props.UsePaintPalette = true; 
   } 
 
   protected override void Dispose(bool disposing) 
   { 
      // Clean up 
      if(disposing) 
      { 
         image.Dispose(); 
         RasterCodecs.Shutdown(); 
      } 
 
      base.Dispose(disposing); 
   } 
 
   protected override void OnPaint(PaintEventArgs e) 
   { 
      // Draw the image fit and center on this form 
      Rectangle destRect = RasterImage.CalculatePaintModeRectangle( 
         image.ImageWidth, 
         image.ImageHeight, 
         ClientRectangle, 
         RasterPaintSizeMode.Fit, 
         RasterPaintAlignMode.Center, 
         RasterPaintAlignMode.Center); 
      image.Paint(e.Graphics, Rectangle.Empty, destRect, props); 
      image.PaintOverlay(e.Graphics, 0, Rectangle.Empty, Rectangle.Empty, destRect, Rectangle.Empty, props); 
 
      base.OnPaint(e); 
   } 
}

Remarks

This method will paint an overlay image. For more information on the paint rectangles, see Paint.

Paint will paint all the overlays that have RasterOverlayAttributes.AutoPaint set to true. The overlays are painted in ascending index order: overlay 0 is painted first, then overlay 1, etc.

Use this method to manually paint an overlay. For example, to change the order in which the overlays are painted, set the RasterOverlayAttributes.AutoPaint property of the overlay to false then call PaintOverlay directly.

To temporarily make an overlay top-most, call PaintOverlay after Paint. To permanently make an overlay top-most, change its index and give it the highest defined index.

The overlay image's 1 pixels are painted with the color set in the RasterOverlayAttributes.Color property of the overlay. The overlay image's 0 pixels are considered transparent.

For more information on the overlay attributes, including the RasterOverlayAttributes.AutoPaint property and the RasterOverlayAttributes.Color property, refer to RasterOverlayAttributes.

For more information, refer to Overlay Overview.

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also