Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
CreateLeadDC Method
See Also  Example
Leadtools Namespace > RasterImage Class : CreateLeadDC Method



Creates a Windows device context using this RasterImage as the display surface.

Syntax

Visual Basic (Declaration)  
Public Function CreateLeadDC() As IntPtr
Visual Basic (Usage) Copy Code
Dim instance As RasterImage
Dim value As IntPtr
 
value = instance.CreateLeadDC()
C#  
public IntPtr CreateLeadDC()
C++/CLI  
public:
IntPtr CreateLeadDC(); 

Return Value

The Win32 HDC this method creates.

Example

This example draws an ellipse on the image.

Visual Basic Copy Code
Public Sub CreateLeadDCExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()
   Dim image As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP")

   Dim StartGDI As Point = New Point(Convert.ToInt32(image.Width / 8), Convert.ToInt32(image.Height / 8))
   Dim EndGDI As Point = New Point(Convert.ToInt32(image.Width \ 2), Convert.ToInt32(image.Height \ 2))

   ' Convert the coordinates if necessary.
   If image.ViewPerspective <> RasterViewPerspective.TopLeft Then
      StartGDI = image.PointToImage(RasterViewPerspective.TopLeft, StartGDI)
      EndGDI = image.PointToImage(RasterViewPerspective.TopLeft, EndGDI)
   End If

   ' Create the device context
   Dim hdc As IntPtr = image.CreateLeadDC()
   Dim pGraphics As Graphics = Graphics.FromHdc(hdc)
   pGraphics.DrawEllipse(New Pen(Color.White), StartGDI.X, StartGDI.Y, EndGDI.X - StartGDI.X, EndGDI.Y - StartGDI.Y)
   RasterImage.DeleteLeadDC(hdc)

   codecs.Save(image, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_LEADDC.BMP", RasterImageFormat.Bmp, 0)

   image.Dispose()
   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C# Copy Code
public void CreateLeadDCExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1.CMP"); 
 
   Point StartGDI = new Point(Convert.ToInt32(image.Width / 8), Convert.ToInt32(image.Height / 8)); 
   Point EndGDI = new Point(Convert.ToInt32(image.Width / 2), Convert.ToInt32(image.Height / 2)); 
 
   // Convert the coordinates if necessary. 
   if(image.ViewPerspective != Leadtools.RasterViewPerspective.TopLeft) 
   { 
      StartGDI = image.PointToImage(Leadtools.RasterViewPerspective.TopLeft, StartGDI); 
      EndGDI = image.PointToImage(Leadtools.RasterViewPerspective.TopLeft, EndGDI); 
   } 
 
   // Create the device context 
   IntPtr hdc = image.CreateLeadDC(); 
   Graphics pGraphics = Graphics.FromHdc(hdc); 
   pGraphics.DrawEllipse(new Pen(Color.White), StartGDI.X, StartGDI.Y, EndGDI.X - StartGDI.X, EndGDI.Y - StartGDI.Y); 
   RasterImage.DeleteLeadDC(hdc); 
 
   codecs.Save(image, LeadtoolsExamples.Common.ImagesPath.Path + "IMAGE1_LEADDC.BMP", RasterImageFormat.Bmp, 0); 
 
   image.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

This method allows you to create an infinite number of drawing capabilities such as paint, erase, color erase and brush, pen, spray gun, flood fill, color tube, text overlay, curve, line, rectangle, polygon, ellipse, freehand shapes, cut and paste, and more.

All Windows GDI functions can be used to draw to the image using the returned HDC. The HDC must be freed with the DeleteLeadDC method.

If a region is defined for the image, GDI functions act only on the region, not on the entire image.

The DIB driver supports only 1, 4, 8, 16 and 24 bit images. If you are using an image that has some other number of bits per pixel, you must use ColorResolutionCommand to change the image to a bits per pixel value supported by the DIB driver.

For more information, refer to Introduction to Image Processing With LEADTOOLS.

Requirements

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

See Also