CreateLeadDC Method
Syntax
Parameters
Return Value
The Windows HDC object this method creates.
Example
This example draws an ellipse on a raster image.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
public void CreateLeadDCExample()
{
RasterCodecs codecs = new RasterCodecs();
RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"));
LeadPoint point1 = new LeadPoint(image.Width / 8, image.Height / 8);
LeadPoint point2 = new LeadPoint(image.Width / 2, image.Height / 2);
// Convert the coordinates if necessary.
if (image.ViewPerspective != RasterViewPerspective.TopLeft)
{
point1 = image.PointToImage(RasterViewPerspective.TopLeft, point1);
point2 = image.PointToImage(RasterViewPerspective.TopLeft, point2);
}
// Create the device context
IntPtr hdc = RasterImagePainter.CreateLeadDC(image);
using (Graphics g = Graphics.FromHdc(hdc))
{
g.DrawEllipse(new Pen(Color.White), point1.X, point1.Y, point2.X - point1.X, point2.Y - point1.Y);
}
RasterImagePainter.DeleteLeadDC(hdc);
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Imahe1_CreateLeadDC.bmp"), RasterImageFormat.Bmp, 0);
image.Dispose();
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
Public Sub CreateLeadDCExample()
Dim codecs As New RasterCodecs()
Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))
Dim point1 As New LeadPoint(image.Width \ 8, image.Height \ 8)
Dim point2 As New LeadPoint(image.Width \ 2, image.Height \ 2)
' Convert the coordinates if necessary.
If image.ViewPerspective <> RasterViewPerspective.TopLeft Then
point1 = image.PointToImage(RasterViewPerspective.TopLeft, point1)
point2 = image.PointToImage(RasterViewPerspective.TopLeft, point2)
End If
' Create the device context
Dim hdc As IntPtr = RasterImagePainter.CreateLeadDC(image)
Using g As Graphics = Graphics.FromHdc(hdc)
g.DrawEllipse(New Pen(Color.White), point1.X, point1.Y, point2.X - point1.X, point2.Y - point1.Y)
End Using
RasterImagePainter.DeleteLeadDC(hdc)
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Imahe1_CreateLeadDC.bmp"), RasterImageFormat.Bmp, 0)
image.Dispose()
codecs.Dispose()
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class