Creates a GDI+
Graphics object using this
RasterImage as the display surface.
Syntax
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"
Dim image As RasterImage = codecs.Load(srcFileName)
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()
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
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also