LEADTOOLS GDI/GDI+ (Leadtools.Drawing assembly)

ConvertToImage Method

Show in webframe
Example 





The source image.
The conversion options.
Converts a LEADTOOLS Leadtools.RasterImage to a GDI+ System.Drawing.Image.
Syntax
public static Image ConvertToImage( 
   RasterImage image,
   ConvertToImageOptions options
)
'Declaration
 
Public Shared Function ConvertToImage( _
   ByVal image As RasterImage, _
   ByVal options As ConvertToImageOptions _
) As Image
'Usage
 
Dim image As RasterImage
Dim options As ConvertToImageOptions
Dim value As Image
 
value = RasterImageConverter.ConvertToImage(image, options)

            

            
public:
static Image^ ConvertToImage( 
   RasterImage^ image,
   ConvertToImageOptions options
) 

Parameters

image
The source image.
options
The conversion options.

Return Value

The GDI+ image this method creates
Remarks

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

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

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

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

For more information, refer to Using The PaintEngine Property.

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

Example
Copy Code  
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Color

Public Sub ConvertToImageExample()
   Dim codecs As New RasterCodecs()

   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
   Dim destFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "GdiPlusImage.bmp")
   Dim destFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_FromGdiPlusImage.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 destImage1 As Image = RasterImageConverter.ConvertToImage(srcImage, ConvertToImageOptions.None)
         ' Save this image to disk
         destImage1.Save(destFileName1, ImageFormat.Bmp)

         ' Convert the GDI+ image back to a RasterImage
         Using destImage2 As RasterImage = RasterImageConverter.ConvertFromImage(destImage1, ConvertFromImageOptions.None)
            ' Save it to disk
            codecs.Save(destImage2, destFileName2, RasterImageFormat.Bmp, 24)
         End Using
      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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Color;

public void ConvertToImageExample()
{
   RasterCodecs codecs = new RasterCodecs();

   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
   string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "GdiPlusImage.bmp");
   string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_FromGdiPlusImage.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 destImage1 = RasterImageConverter.ConvertToImage(srcImage, ConvertToImageOptions.None))
      {
         // Save this image to disk
         destImage1.Save(destFileName1, ImageFormat.Bmp);

         // Convert the GDI+ image back to a RasterImage
         using(RasterImage destImage2 = RasterImageConverter.ConvertFromImage(destImage1, ConvertFromImageOptions.None))
         {
            // Save it to disk
            codecs.Save(destImage2, destFileName2, RasterImageFormat.Bmp, 24);
         }
      }
   }

   // Clean up
   codecs.Dispose();
}

static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
Requirements

Target Platforms

See Also

Reference

RasterImageConverter Class
RasterImageConverter Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.