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"
Dim srcImage As RasterImage = codecs.Load(srcFileName)
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()
destImage1.Save(destFileName1, ImageFormat.Bmp)
Dim destImage2 As RasterImage = New RasterImage(destImage1)
codecs.Save(destImage2, destFileName2, RasterImageFormat.Bmp, 24)
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
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also