←Select platform

ConvertToImageOptions Enumeration

Summary
Options to use when converting a LEADTOOLS Leadtools.RasterImage object to GDI+ System.Drawing.Bitmap.
Syntax
C#
C++/CLI
Python
[FlagsAttribute()] 
public enum ConvertToImageOptions   
[FlagsAttribute()] 
public enum class ConvertToImageOptions   
class ConvertToImageOptions(Enum): 
   None = 0 
   InitAlpha = 1 
Members
ValueMemberDescription
0x00000000None Default
0x00000001InitAlpha Initialize the destination image alpha values if supported (when the result of the conversion is a 32 or 64-bit image). If this flagged is specified, the result image will always have an alpha value of all 1's (255 for 32-bit images or 65535 for 64-bit images) regardless of the alpha values in the source image. This can be useful when converting some 32-bit images that may have 0 for the alpha (such as BMP files) which translates into an GDI+ image that is completely transparent. If this flag is not specified, then the source image alpha values will be used as is.
Remarks

The ConvertToImageOptions are used as an options for the RasterImageConverter.ConvertToImage method.

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

Example
C#
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:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

Leadtools.Drawing Namespace

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

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