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



srcImage
The Image from which to create the new RasterImage.
Constructs a new RasterImage from the specified existing GDI+ Image object.

Syntax

Visual Basic (Declaration)  
Public Function New( _
   ByVal srcImage As Image _
)
Visual Basic (Usage) Copy Code
Dim srcImage As Image
 
Dim instance As RasterImage(srcImage)
C#  
public RasterImage( 
   Image srcImage
)
C++/CLI  
public:
RasterImage( 
   Image srcImage
)

Parameters

srcImage
The Image from which to create the new RasterImage.

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

For information about 16bpp grayscale images, refer to The RasterPaintEngine Property and 16bpp Grayscale Images.

Requirements

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

See Also