LEADTOOLS GDI/GDI+ (Leadtools.Drawing assembly)

CreateGraphics Method

Show in webframe
Example 





The source image.
Creates a GDI+ System.Drawing.Graphics object using this Leadtools.RasterImage as the display surface.
Syntax
public static RasterGraphics CreateGraphics( 
   RasterImage image
)
'Declaration
 
Public Shared Function CreateGraphics( _
   ByVal image As RasterImage _
) As RasterGraphics
'Usage
 
Dim image As RasterImage
Dim value As RasterGraphics
 
value = RasterImagePainter.CreateGraphics(image)

            

            
public:
static RasterGraphics^ CreateGraphics( 
   RasterImage^ image
) 

Parameters

image
The source image.

Return Value

The GDI+ System.Drawing.Graphics object this method creates.
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 GDI+ methods can be used to draw to the image using the returned System.Drawing.Graphics object. The graphics object must be disposed after using it.

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

The GDI+ graphics 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 Leadtools.ImageProcessing.ColorResolutionCommand to change the image to a bits per pixel value supported by the DIB driver.

For more information refer to RasterImage and GDI/GDI+.

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

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing

Public Sub CreateGraphicsExample()
   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 Graphics object
   Using rg As RasterGraphics = RasterImagePainter.CreateGraphics(image)
      rg.Graphics.DrawEllipse(New Pen(Color.White), point1.X, point1.Y, point2.X - point1.X, point2.Y - point1.Y)
   End Using

   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_CreateGraphics.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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;

public void CreateGraphicsExample()
{
   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 Graphics object
   using(RasterGraphics rg = RasterImagePainter.CreateGraphics(image))
   {
      rg.Graphics.DrawEllipse(new Pen(Color.White), point1.X, point1.Y, point2.X - point1.X, point2.Y - point1.Y);
   }

   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_CreateGraphics.bmp"), RasterImageFormat.Bmp, 0);

   image.Dispose();
   codecs.Dispose();
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms

See Also

Reference

RasterImagePainter Class
RasterImagePainter Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.