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



flags
Options for the conversion.
Changes this RasterImage to a GDI+ Image.

Syntax

Visual Basic (Declaration) 
Public Function ChangeToGdiPlusImage( _
   ByVal flags As ChangeToGdiPlusImageFlags _
) As Image
Visual Basic (Usage)Copy Code
Dim instance As RasterImage
Dim flags As ChangeToGdiPlusImageFlags
Dim value As Image
 
value = instance.ChangeToGdiPlusImage(flags)
C# 
public Image ChangeToGdiPlusImage( 
   ChangeToGdiPlusImageFlags flags
)
C++/CLI 
public:
Image ChangeToGdiPlusImage( 
   ChangeToGdiPlusImageFlags flags
) 

Parameters

flags
Options for the conversion.

Return Value

The GDI+ image that this method creates.

Example

This example changes between a RasterImage and a GDI+ image

Visual BasicCopy Code
Public Sub ChangeToGdiPlusImageExample()
   RasterCodecs.Startup()
   Dim codecs As RasterCodecs = New RasterCodecs()

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

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

   ' Convert to GDI+ image
   Console.WriteLine("TestGdiPlusCompatible: {0}", (srcImage.TestGdiPlusCompatible(True)).ToString())
   Console.WriteLine("NearestGdiPlusPixelFormat:{0}", (srcImage.NearestGdiPlusPixelFormat).ToString())

   If srcImage.TestGdiPlusCompatible(True) <> RasterGdiPlusIncompatibleReason.Compatible Then
      srcImage.MakeGdiPlusCompatible(srcImage.NearestGdiPlusPixelFormat, True)
   End If

   Dim destImage As Image = srcImage.ChangeToGdiPlusImage(ChangeToGdiPlusImageFlags.ForceChange)

   ' Save this image to disk
   destImage.Save(destFileName, ImageFormat.Bmp)

   ' Clean up
   destImage.Dispose()
   srcImage.Dispose()
   codecs.Dispose()
   RasterCodecs.Shutdown()
End Sub
C#Copy Code
public void ChangeToGdiPlusImageExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "GdiPlusImage1.bmp"; 
 
   // Load the image 
   RasterImage srcImage = codecs.Load(srcFileName); 
 
   // Convert to GDI+ image 
   Console.WriteLine("TestGdiPlusCompatible: {0}", (srcImage.TestGdiPlusCompatible(true)).ToString()); 
   Console.WriteLine("NearestGdiPlusPixelFormat:{0}", (srcImage.NearestGdiPlusPixelFormat).ToString()); 
 
   if(srcImage.TestGdiPlusCompatible(true) != RasterGdiPlusIncompatibleReason.Compatible) 
      srcImage.MakeGdiPlusCompatible(srcImage.NearestGdiPlusPixelFormat, true); 
 
   Image destImage = srcImage.ChangeToGdiPlusImage(ChangeToGdiPlusImageFlags.ForceChange); 
 
   // Save this image to disk 
   destImage.Save(destFileName, ImageFormat.Bmp); 
 
   // Clean up 
   destImage.Dispose(); 
   srcImage.Dispose(); 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

This result GDI+ image and this RasterImage object will share the same image data. You can use this method to pass a LEAD RasterImage object to other class library methods that expect a GDI+ Image object. Use the ConvertToGdiPlusImage method to obtain a GDI+ Image object that is a copy of this RasterImage object.

Calling this method may change the internal format of this RasterImage object.

Use TestGdiPlusCompatible to determine if the image is compatible for conversion to a GDI+ image.

For a RasterImage to be compatible with a GDI+ image it needs the following:

For more information, refer to The RasterPaintEngine Property and 16bpp Grayscale Images and Using The PaintEngine Property.

Requirements

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

See Also