←Select platform

RasterImageConverter Class

Summary
Converts a LEADTOOLS Leadtools.RasterImage to and from GDI and GDI+ image objects.
Syntax
C#
VB
C++
public static class RasterImageConverter 
Public MustInherit NotInheritable Class RasterImageConverter  
public ref class RasterImageConverter abstract sealed  
Remarks

The LEADTOOLS RasterImage class provides platform-independent representation of an image. It serves as a working area for image manipulation and conversion. LEADTOOLS functions use this class for accessing the image in memory and for maintaining the characteristics of the image. This class contains the functionality for converting a LEADTOOLS Leadtools.RasterImage to and from a Windows GDI or GDI+ image objects.

The RasterImageConverter class contains the following functionality:

Method Description
ConvertToImage

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

ConvertFromImage

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

ChangeToImage

Converts a LEADTOOLS Leadtools.RasterImage to GDI+ System.Drawing.Image sharing the same memory.

MakeCompatible

Makes a Leadtools.RasterImage pixel and color format compatible with GDI+

TestCompatible, GetNearestBitsPerPixel, IsValidBitsPerPixel and GetNearestPixelFormat

Utility methods for testing and making a LEADTOOLS Leadtools.RasterImage GDI+ compatible

FromHBitmap and ToHBitmap

Converts a Leadtools.RasterImage to and from a GDI DDB (Device Dependant Bitmap)

ChangeFromHBitmap and ChangeToHBitmap

Converts a Leadtools.RasterImage to and from a GDI DDB (Device Dependant Bitmap) while sharing the same memory

ToWmf, FromWmf, ToEmf and FromEmf

Converts a Leadtools.RasterImage to and from a Windows Metafile or Enhanced Metafile

ChangeToWmf, ChangeFromWmf, ChangeToEmf and ChangeFromEmf

Converts a Leadtools.RasterImage to and from a Windows Metafile or Enhanced Metafile while sharing the same memory

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

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
 
 
public void RasterImageConverterExample() 
{ 
   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, "RasterImage.bmp"); 
 
   // Load a RasterImage, convert to GDI+ image 
   using (RasterImage leadImage = codecs.Load(srcFileName)) 
   { 
      // Convert to GDI+ image 
      using (Image gdipImage = RasterImageConverter.ConvertToImage(leadImage, ConvertToImageOptions.None)) 
      { 
         // Save it to disk 
         gdipImage.Save(destFileName1, ImageFormat.Bmp); 
      } 
   } 
 
   // Load a GDI+ image, convert to RasterImage 
   using (Image gdipImage = Image.FromFile(destFileName1)) 
   { 
      // Convert to RasterImage 
      using (RasterImage leadImage = RasterImageConverter.ConvertFromImage(gdipImage, ConvertFromImageOptions.None)) 
      { 
         // Save it to disk 
         codecs.Save(leadImage, destFileName2, RasterImageFormat.Bmp, 0); 
      } 
   } 
 
   // Clean up 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Drawing 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Color 
 
Public Sub RasterImageConverterExample() 
   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, "RasterImage.bmp") 
 
   ' Load a RasterImage, convert to GDI+ image 
   Using leadImage As RasterImage = codecs.Load(srcFileName) 
      ' Convert to GDI+ image 
      Using gdipImage As Image = RasterImageConverter.ConvertToImage(leadImage, ConvertToImageOptions.None) 
         ' Save it to disk 
         gdipImage.Save(destFileName1, ImageFormat.Bmp) 
      End Using 
   End Using 
 
   ' Load a GDI+ image, convert to RasterImage 
   Using gdipImage As Image = Image.FromFile(destFileName1) 
      ' Convert to RasterImage 
      Using leadImage As RasterImage = RasterImageConverter.ConvertFromImage(gdipImage, ConvertFromImageOptions.None) 
         ' Save it to disk 
         codecs.Save(leadImage, destFileName2, RasterImageFormat.Bmp, 0) 
      End Using 
   End Using 
 
   ' Clean up 
   codecs.Dispose() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images" 
End Class 
Requirements

Target Platforms

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Drawing Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.