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



Converts this RasterImage to a GDI+ image.

Syntax

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

Return Value

The GDI+ image this method creates

Example

This example converts between a RasterImage and a GDI+ image

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

   Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
   Dim destFileName1 As String = LeadtoolsExamples.Common.ImagesPath.Path + "GdiPlusImage.bmp"
   Dim destFileName2 As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_FromGdiPlusImage.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 destImage1 As Image = srcImage.ConvertToGdiPlusImage()

   ' Save this image to disk
   destImage1.Save(destFileName1, ImageFormat.Bmp)

   ' Convert the GDI+ image back to a RasterImage
   Dim destImage2 As RasterImage = New RasterImage(destImage1)

   ' Save it to disk
   codecs.Save(destImage2, destFileName2, RasterImageFormat.Bmp, 24)

   ' Clean up
   destImage2.Dispose()
   destImage1.Dispose()
   srcImage.Dispose()

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

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName1 = LeadtoolsExamples.Common.ImagesPath.Path + "GdiPlusImage.bmp"; 
   string destFileName2 = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_FromGdiPlusImage.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 destImage1 = srcImage.ConvertToGdiPlusImage(); 
 
   // Save this image to disk 
   destImage1.Save(destFileName1, ImageFormat.Bmp); 
 
   // Convert the GDI+ image back to a RasterImage 
   RasterImage destImage2 = new RasterImage(destImage1); 
 
   // Save it to disk 
   codecs.Save(destImage2, destFileName2, RasterImageFormat.Bmp, 24); 
 
   // Clean up 
   destImage2.Dispose(); 
   destImage1.Dispose(); 
   srcImage.Dispose(); 
 
   codecs.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Remarks

This result GDI+ image is a copy of this RasterImage object and do not 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 ChangeToGdiPlusImage method to obtain a GDI+ Image object that shares its data with 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