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



Creates a GDI+ Graphics object using this RasterImage as the display surface.

Syntax

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

Return Value

The RasterImageGdiPlusGraphicsContainer object this method creates.

Example

This example loads an image then gets a Graphics object for its surface.

Visual Basic Copy Code
Public Sub CreateGdiPlusGraphicsExample()
   RasterCodecs.Startup()
   Dim codecs As New RasterCodecs()

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_CreateGdiPlusGraphics.bmp"

   ' Load the image
   Dim image As RasterImage = codecs.Load(srcFileName)

   ' Create a graphics object for this image surface and draw something on it
   Dim container As RasterImageGdiPlusGraphicsContainer = image.CreateGdiPlusGraphics()
   Dim g As Graphics = container.Graphics
   Dim b As New SolidBrush(Color.FromArgb(128, 0, 0, 0))
   g.FillEllipse(b, New Rectangle(0, 0, image.ImageWidth, image.ImageHeight))
   b.Dispose()
   container.Dispose()

   ' Save the image back on disk
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24)

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

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_CreateGdiPlusGraphics.bmp"; 
 
   // Load the image 
   RasterImage image = codecs.Load(srcFileName); 
 
   // Create a graphics object for this image surface and draw something on it 
   RasterImageGdiPlusGraphicsContainer container = image.CreateGdiPlusGraphics(); 
   Graphics g = container.Graphics; 
   Brush b = new SolidBrush(Color.FromArgb(128, 0, 0, 0)); 
   g.FillEllipse(b, new Rectangle(0, 0, image.ImageWidth, image.ImageHeight)); 
   b.Dispose(); 
   container.Dispose(); 
 
   // Save the image back on disk 
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); 
 
   image.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

Use TestGdiPlusCompatible to determine if the image is compatible for creating a GDI+ Graphics object.

This 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 to use on the surface of this RasterImage.

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