←Select platform

ChangeToImage Method

Summary

Changes a LEADTOOLS Leadtools.RasterImage to a GDI+ System.Drawing.Image.

Syntax

C#
VB
C++
public static Image ChangeToImage( 
   RasterImage image, 
   ChangeToImageOptions options 
) 
Public Shared Function ChangeToImage( _ 
   ByVal image As Leadtools.RasterImage, _ 
   ByVal options As Leadtools.Drawing.ChangeToImageOptions _ 
) As Image 

Parameters

image
The source image.

options
The conversion options.

Return Value

The GDI+ image that this method creates.

Remarks

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

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

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

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

To convert a GDI+ image to a LEADTOOLS Leadtools.RasterImage, use ConvertFromImage.

For more information, refer to Using The PaintEngine Property.

For more information refer to RasterImage and GDI/GDI+.

Example

This example changes between a Leadtools.RasterImage and a GDI+ image.

C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
public void ChangeToImageExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
   string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "GdiPlusImage1.bmp"); 
 
   // Load the image 
   using (RasterImage srcImage = codecs.Load(srcFileName)) 
   { 
      // Convert to GDI+ image 
      ImageIncompatibleReason reason = RasterImageConverter.TestCompatible(srcImage, true); 
      PixelFormat pf = RasterImageConverter.GetNearestPixelFormat(srcImage); 
      Console.WriteLine("TestCompatible: {0}", reason); 
      Console.WriteLine("GetNearestPixelFormat:{0}", pf); 
 
      if (reason != ImageIncompatibleReason.Compatible) 
      { 
         RasterImageConverter.MakeCompatible(srcImage, pf, true); 
      } 
 
      using (Image destImage = RasterImageConverter.ChangeToImage(srcImage, ChangeToImageOptions.ForceChange)) 
      { 
         // Save this image to disk 
         destImage.Save(destFileName, ImageFormat.Bmp); 
      } 
   } 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Drawing 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
 
Public Sub ChangeToImageExample() 
   Dim codecs As New RasterCodecs() 
 
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") 
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "GdiPlusImage1.bmp") 
 
   ' Load the image 
   Using srcImage As RasterImage = codecs.Load(srcFileName) 
      ' Convert to GDI+ image 
      Dim reason As ImageIncompatibleReason = RasterImageConverter.TestCompatible(srcImage, True) 
      Dim pf As PixelFormat = RasterImageConverter.GetNearestPixelFormat(srcImage) 
      Console.WriteLine("TestCompatible: {0}", reason) 
      Console.WriteLine("GetNearestPixelFormat:{0}", pf) 
 
      If reason <> ImageIncompatibleReason.Compatible Then 
         RasterImageConverter.MakeCompatible(srcImage, pf, True) 
      End If 
 
      Using destImage As Image = RasterImageConverter.ChangeToImage(srcImage, ChangeToImageOptions.ForceChange) 
         ' Save this image to disk 
         destImage.Save(destFileName, ImageFormat.Bmp) 
      End Using 
   End Using 
 
   ' Clean up 
   codecs.Dispose() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Drawing Assembly