←Select platform

IsValidBitsPerPixel Method

Summary
Determines whether the specified bits per pixel value supported by LEADTOOLS is compatible with GDI+.
Syntax
C#
C++/CLI
Python
public static bool IsValidBitsPerPixel( 
   int bitsPerPixel 
) 
public: 
static bool IsValidBitsPerPixel(  
   int bitsPerPixel 
)  
def IsValidBitsPerPixel(self,bitsPerPixel): 

Parameters

bitsPerPixel
The input bits per pixel value.

Return Value

true if  bitsPerPixel is compatible with GDI+, otherwise it is false.

Remarks

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 IsValidBitsPerPixelExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
   using (RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"))) 
   { 
      // check if this image has a valid gdi plus bits/pixel.  It should say true 
      if (RasterImageConverter.IsValidBitsPerPixel(image.BitsPerPixel)) 
      { 
         Console.WriteLine(string.Format("{0} is a valid GDI+ bits/pixel", image.BitsPerPixel)); 
      } 
      else 
      { 
         Console.WriteLine(string.Format("{0} is not a valid GDI+ bits/pixel", image.BitsPerPixel)); 
      } 
 
      // change this image to grayscale 12-bit 
      ColorResolutionCommand cmd = new ColorResolutionCommand( 
         ColorResolutionCommandMode.InPlace, 
         12, 
         RasterByteOrder.Gray, 
         RasterDitheringMethod.None, 
         ColorResolutionCommandPaletteFlags.Optimized, 
         null); 
 
      cmd.Run(image); 
 
      // check if this image has a valid gdi plus bits/pixel.  It should say false 
      if (RasterImageConverter.IsValidBitsPerPixel(image.BitsPerPixel)) 
      { 
         Console.WriteLine(string.Format("{0} is a valid GDI+ bits/pixel", image.BitsPerPixel)); 
      } 
      else 
      { 
         Console.WriteLine(string.Format("{0} is not a valid GDI+ bits/pixel", image.BitsPerPixel)); 
      } 
   } 
 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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