←Select platform

NoImageDataConversion Property

Summary
Gets or sets a value indicating whether image data is automatically converted during load.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public bool NoImageDataConversion { get; set; } 
@property (nonatomic, assign) BOOL NoImageDataConversion; 
public boolean getNoImageDataConversion() 
public void setNoImageDataConversion(boolean value) 
public: 
property bool NoImageDataConversion { 
   bool get(); 
   void set (    bool ); 
} 
NoImageDataConversion # get and set (CodecsLoadOptions) 

Property Value

Value Description
true To prevent conversion of of image data. This allows you to load floating point images.
false To allow automatic conversion of image data. The default value is false.
Remarks

LEADTOOLS will sometimes automatically convert some image data during load to ensure proper display. Some of the situations are listed below: 1) Floating point values from some TIFF or GeoTIFF files are automatically scaled and converted to integer. The scale is done to take the minimum value to black and maximum value to white. 2) Data in some JPEG-LS files is automatically converted to ensure proper display. (Without this conversion, some images would look all black).

Applications that need more control over the image data can set NoImageDataConversion to true prevents this automatic conversion. But in this case, the application might need to perform extra steps before the image can be displayed properly.

If you set NoImageDataConversion to true and load a TIFF/GeoTIFF with floating point values, you will obtain a floating point image. This will allow you to perform certain calculations over the floating point data. But LEADTOOLS has minimal support for images with floating point pixels, which is why the floating point values are converted and scaled during load by default.

For support details on the image's floating point pixels, refer to Working With Floating Point Images.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
 
using Leadtools.ImageProcessing.Core; 
using Leadtools.Pdf; 
 
 
public void TestLoadFloat() 
{ 
   //This example loads floating point values from a GeoTIFF file. It extracts data from the image and examines a few pixel values. 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      string srcFile = Path.Combine(LEAD_VARS.ImagesDir, "test_GeoKey.TIF"); 
      codecs.Options.Load.NoImageDataConversion = true; 
      using (RasterImage image = codecs.Load(srcFile, 1)) 
      { 
         // RasterImage.Float will be true if the image was loaded with floating point pixels 
         Debug.WriteLine($"RasterImage.Float = {image.Float}"); 
 
         /* Allocate an unmanaged pointer for getting row data. The buffer size is in bytes, so we need to use image.BytesPerLine or image.Width*4  */ 
         IntPtr buffer = Marshal.AllocHGlobal(image.BytesPerLine); 
 
         image.Access(); 
 
         /* get the floating point data for row 186 into an unmanaged pointer. If your image does not have 187 rows, adjust the row number */ 
         image.GetRow(186, buffer, image.BytesPerLine); 
 
         /* You can't cast to float in C#, so we will need to allocate a managed array of float values and copy the unmanaged data into it */ 
         float[] floatBuf = new float[image.Width]; 
         // Note that copy should use image.Width, not image.BytesPerLine! 
         Marshal.Copy(buffer, floatBuf, 0, image.Width); 
         image.Release(); 
 
         /* Examine a few pixels from line. If the values are garbage, make sure RasterImage.Float = true. If RasterImage.Float = false, then the source file did not have floating point values */ 
         Debug.WriteLine($"Line 186: [146] = {floatBuf[146]}, [421] = {floatBuf[421]}, [568] = {floatBuf[568]}"); 
 
         // Free the unmanaged pointer 
         Marshal.FreeHGlobal(buffer); 
      } 
   } 
} 
 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.nio.file.Paths; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.core.MinMaxBitsCommand; 
 
 
// This example loads floating point values from a GeoTIFF file. It extracts 
// data from the image and examines a few pixel values. 
public void codecsNoImageDataConversionExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   String srcFile = combine(LEAD_VARS_IMAGES_DIR, "barcode1.tif"); 
   codecs.getOptions().getLoad().setNoImageDataConversion(true); 
   RasterImage image = codecs.load(srcFile, 1); 
 
   // RasterImage.Float will be true if the image was loaded with floating point 
   // pixels 
   System.out.printf("RasterImage.Float = %s%n", image.getFloat()); 
 
   // Allocate an unmanaged pointer for getting row data. The buffer size is in 
   // bytes, so we need to use image.BytesPerLine or image.Width*4 // 
   byte[] buffer = new byte[image.getBytesPerLine()]; 
 
   image.access(); 
 
   // get the floating point data for row 186 into an unmanaged pointer. If your 
   // image does not have 187 rows, adjust the row number // 
   image.getRow(186, buffer, image.getBytesPerLine()); 
 
   // You can't cast to float in C#, so we will need to allocate a managed array of 
   // float values and copy the unmanaged data into it // 
   float[] floatBuf = new float[image.getWidth()]; 
 
   // Note that copy should use image.Width, not image.BytesPerLine! 
   for (int i = 0; i < buffer.length; i++) { 
      buffer[i] = (byte) floatBuf[i]; 
   } 
 
   assertTrue("bytes unsuccessfully transferred from floatBuf to buffer", buffer[3] == (byte) floatBuf[3]); 
   assertTrue("bytes unsuccessfully transferred from floatBuf to buffer", buffer[10] == (byte) floatBuf[10]); 
   assertTrue("bytes unsuccessfully transferred from floatBuf to buffer", buffer[17] == (byte) floatBuf[17]); 
   assertTrue("bytes unsuccessfully transferred from floatBuf to buffer", buffer[22] == (byte) floatBuf[22]); 
   assertTrue("bytes unsuccessfully transferred from floatBuf to buffer", buffer[37] == (byte) floatBuf[37]); 
   assertTrue("bytes unsuccessfully transferred from floatBuf to buffer", buffer[40] == (byte) floatBuf[40]); 
   System.out.println("Bytes transferred properly from floatBuf to buffer"); 
 
   image.release(); 
 
   // Examine a few pixels from line. If the values are garbage, make sure 
   // RasterImage.Float = true. If RasterImage.Float = false, then the source file 
   // did not have floating point values // 
   System.out.printf("Line 186: [146] = %s, [300] = %s, [347] = %s%n", floatBuf[146], floatBuf[300], floatBuf[347]); 
 
   // Free the unmanaged pointer 
   buffer = null; 
} 
Requirements

Target Platforms

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

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