←Select platform

Format Property

Summary
Gets the image file format.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterImageFormat Format { get; set; } 
@property (nonatomic, assign) LTRasterImageFormat format; 
public RasterImageFormat getFormat() 
public void setFormat(RasterImageFormat value) 
public: 
property RasterImageFormat Format { 
   RasterImageFormat get(); 
   void set (    RasterImageFormat ); 
} 
Format # get and set (CodecsLoadInformationEventArgs) 

Property Value

The image file format. The following are valid formats:

Value Meaning
RasterImageFormat.FaxG31Dim Fax file with G3 one-dimensional compression
RasterImageFormat.FaxG32Dim Fax file with G3 two-dimensional compression
RasterImageFormat.FaxG4 Fax file with G4 compression
RasterImageFormat.RawRle4 RAW file with RLE compression, 4 bits per pixel
RasterImageFormat.RawRle8 RAW file with RLE compression, 8 bits per pixel
RasterImageFormat.RawBitfields RAW file with bitfield compression
RasterImageFormat.RawPackBits RAW file with packed bits compression
RasterImageFormat.RawCcitt RAW file with CCITT compression
RasterImageFormat.Raw RAW file
RasterImageFormat.RawLzw RAW file with LZW compression
RasterImageFormat.RawJpeg RAW file with JPEG compression
RasterImageFormat.Raw RAW file
Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Svg; 
 
 
private struct RawData 
{ 
   public int Width;                               // Width of image 
   public int Height;                              // Height of image 
   public int BitsPerPixel;                        // Bits per pixel of image--if palettized, a gray palette is generated 
   public RasterViewPerspective ViewPerspective;   // View perspective of raw data (TopLeft, BottomLeft, etc) 
   public RasterByteOrder Order;                   // Rgb or Bgr 
   public int XResolution;                         // Horizontal resolution in DPI 
   public int YResolution;                         // Vertical resolution in DPI 
   public int Offset;                              // Offset into file where raw data begins 
   public bool Padding;                            // true if each line of data is padded to four bytes 
   public bool ReverseBits;                        // true if the bits of each byte are reversed  
} 
 
private RawData myRawData; 
 
private void codecs_LoadInformation(object sender, CodecsLoadInformationEventArgs e) 
{ 
   // Set the information 
   e.Format = RasterImageFormat.Raw; 
   e.Width = myRawData.Width; 
   e.Height = myRawData.Height; 
   e.BitsPerPixel = myRawData.BitsPerPixel; 
   e.XResolution = myRawData.XResolution; 
   e.YResolution = myRawData.YResolution; 
   e.Offset = myRawData.Offset; 
   e.MotorolaOrder = false; 
   e.PhotoInterpolation = CodecsPhotoInterpolation.WhiteIsZero; 
   e.PlanarConfiguration = CodecsPlanarConfiguration.PlanarFormat; // This value is used only if Format is RasterImageFormat.RawPackBits 
   e.Reverse = true; 
   e.StripSize = 10; 
   e.WhiteOnBlack = false; 
   e.GetPalette(); 
 
   Debug.WriteLine($"Stream: {e.Stream.ToString()}"); 
 
   if (myRawData.Padding) 
      e.Pad4 = true; 
 
   e.Order = myRawData.Order; 
 
   if (myRawData.ReverseBits) 
      e.LeastSignificantBitFirst = true; 
 
   e.ViewPerspective = myRawData.ViewPerspective; 
 
   // If image is palettized create a grayscale palette 
   if (e.BitsPerPixel <= 8) 
   { 
      int colors = 1 << e.BitsPerPixel; 
      RasterColor[] palette = new RasterColor[colors]; 
      for (int i = 0; i < palette.Length; i++) 
      { 
         byte val = (byte)((i * 255) / (colors - 1)); 
         palette[i] = new RasterColor(val, val, val); 
      } 
 
      e.SetColorMask(palette); 
      e.SetPalette(palette); 
   } 
} 
public void LoadInformationExample() 
{ 
   // First, load a JPEG or CMP file 
   string srcFilename = Path.Combine(LEAD_VARS.ImagesDir, "IMAGE2.CMP"); 
   string rawFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.raw"); 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.Load(srcFilename); 
 
   // Save this image as RAW data 
 
   // Set RAW options 
   codecs.Options.Raw.Save.Pad4 = true; 
   codecs.Options.Raw.Save.ReverseBits = true; 
   codecs.Options.Save.OptimizedPalette = true; 
 
   codecs.Save(image, rawFileName, RasterImageFormat.Raw, 0); 
 
   // Save information about this image so we can use it to load the RAW file 
   myRawData = new RawData(); 
   myRawData.Width = image.Width; 
   myRawData.Height = image.Height; 
   myRawData.BitsPerPixel = image.BitsPerPixel; 
   myRawData.ViewPerspective = image.ViewPerspective; 
   myRawData.Order = image.Order; 
   myRawData.XResolution = image.XResolution; 
   myRawData.YResolution = image.YResolution; 
   myRawData.Offset = 0; 
   myRawData.Padding = true; 
   myRawData.ReverseBits = true; 
 
   // We dont need the image anymore 
   image.Dispose(); 
 
   // Now load this RAW image back 
 
   // First subscribe to the LoadInformation event so we can set the image information 
   codecs.LoadInformation += new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation); 
 
   // Load the image 
   image = codecs.Load(rawFileName); 
 
   // Unsubscribe from the event 
   codecs.LoadInformation -= new EventHandler<CodecsLoadInformationEventArgs>(codecs_LoadInformation); 
 
   // save it as bmp for testing 
   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Image1_raw.bmp"), RasterImageFormat.Bmp, 0); 
 
   // Clean up 
   image.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.*; 
import java.net.*; 
import java.nio.file.Paths; 
import java.util.*; 
import java.time.Instant; 
import java.time.Duration; 
 
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.codecs.RasterCodecs.FeedCallbackThunk; 
import leadtools.drawing.internal.*; 
import leadtools.imageprocessing.*; 
import leadtools.imageprocessing.color.ChangeIntensityCommand; 
import leadtools.svg.*; 
 
 
private class RawData { 
 
   public int Width; // Width of image 
   public int Height; // Height of image 
   public int BitsPerPixel; // Bits per pixel of image--if palettized, a gray palette is generated 
   public RasterViewPerspective ViewPerspective; // View perspective of raw data (TopLeft, BottomLeft, etc) 
   public RasterByteOrder Order; // Rgb or Bgr 
   public int XResolution; // Horizontal resolution in DPI 
   public int YResolution; // Vertical resolution in DPI 
   public int Offset; // Offset into file where raw data begins 
   public boolean Padding; // true if each line of data is padded to four bytes 
   public boolean ReverseBits; // true if the bits of each byte are reversed 
 
} 
 
private RawData myRawData; 
 
CodecsLoadInformationListener codecsLoadInformation = new CodecsLoadInformationListener() { 
 
   @Override 
   public void onLoadInformation(CodecsLoadInformationEvent e) { 
      // Set the information 
      e.setFormat(RasterImageFormat.RAW); 
      e.setWidth(myRawData.Width); 
      e.setHeight(myRawData.Height); 
      e.setBitsPerPixel(myRawData.BitsPerPixel); 
      e.setXResolution(myRawData.XResolution); 
      e.setYResolution(myRawData.YResolution); 
      e.setOffset(myRawData.Offset); 
      e.setMotorolaOrder(false); 
      e.setPhotoInterpolation(CodecsPhotoInterpolation.WHITE_IS_ZERO); 
      e.setPlanarConfiguration(CodecsPlanarConfiguration.PLANAR_FORMAT); // This value is used only if Format is 
 
      // RasterImageFormat.RawPackBits 
      e.setReverse(true); 
      e.setStripSize(10); 
      e.setWhiteOnBlack(false); 
      e.getPalette(); 
 
      System.out.println("Stream: " + e.getStream().toString()); 
 
      if (myRawData.Padding) 
         e.setPad4(true); 
 
      e.setOrder(myRawData.Order); 
 
      if (myRawData.ReverseBits) 
         e.setLeastSignificantBitFirst(true); 
 
      e.setViewPerspective(myRawData.ViewPerspective); 
 
      // If image is palettized create a grayscale palette 
      if (e.getBitsPerPixel() <= 8) { 
         int colors = 1 << e.getBitsPerPixel(); 
         RasterColor[] palette = new RasterColor[colors]; 
         int[] mask = new int[colors]; 
         for (int i = 0; i < palette.length; i++) { 
            byte val = (byte) ((i * 255) / (colors - 1)); 
            palette[i] = new RasterColor(val, val, val); 
            mask[i] = val; 
         } 
 
         e.setColorMask(mask); 
         e.setPalette(palette); 
      } 
   } 
 
}; 
 
public void loadInformationExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   // First, load a JPEG or CMP file 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image2.cmp"); 
   String rawFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.raw"); 
   RasterCodecs codecs = new RasterCodecs(); 
   RasterImage image = codecs.load(srcFileName); 
 
   // Set RAW options 
   codecs.getOptions().getRaw().getSave().setPad4(true); 
   codecs.getOptions().getRaw().getSave().setReverseBits(true); 
   codecs.getOptions().getSave().setOptimizedPalette(true); 
 
   // Save this image as RAW data 
   codecs.save(image, rawFileName, RasterImageFormat.RAW, 0); 
 
   assertTrue("File unsuccessfully saved", (new File(rawFileName)).exists()); 
   System.out.println("File successfully saved to: " + rawFileName); 
 
   // Save information about this image so we can use it to load the RAW file 
   myRawData = new RawData(); 
   myRawData.Width = image.getWidth(); 
   myRawData.Height = image.getHeight(); 
   myRawData.BitsPerPixel = image.getBitsPerPixel(); 
   myRawData.ViewPerspective = image.getViewPerspective(); 
   myRawData.Order = image.getOrder(); 
   myRawData.XResolution = image.getXResolution(); 
   myRawData.YResolution = image.getYResolution(); 
   myRawData.Offset = 0; 
   myRawData.Padding = true; 
   myRawData.ReverseBits = true; 
 
   // We dont need the image anymore 
   image.dispose(); 
 
   // Now load this RAW image back 
   // First subscribe to the LoadInformation event so we can set the image 
   // information 
   codecs.addLoadInformationListener(codecsLoadInformation2); 
 
   // Load the image 
   ILeadStream rawFileStream = LeadStreamFactory.create(rawFileName); 
   image = codecs.load(rawFileStream); 
 
   // Unsubscribe from the event 
   codecs.removeLoadInformationListener(codecsLoadInformation2); 
 
   // save it as bmp for testing 
   codecs.save(image, combine(LEAD_VARS_IMAGES_DIR, "Image1_raw.bmp"), RasterImageFormat.BMP, 0); 
   assertTrue("RasterImage unsuccessfully saved to" + combine(LEAD_VARS_IMAGES_DIR, "Image1_raw.bmp"), 
         (new File(combine(LEAD_VARS_IMAGES_DIR, "Image1_raw.bmp"))).exists()); 
   System.out.println("RasterImage saved to" + combine(LEAD_VARS_IMAGES_DIR, "Image1_raw.bmp")); 
 
   // Clean up 
   image.dispose(); 
   codecs.dispose(); 
} 
 
CodecsLoadInformationListener codecsLoadInformation2 = new CodecsLoadInformationListener() { 
   @Override 
   public void onLoadInformation(CodecsLoadInformationEvent e) { 
      // Set the information 
      e.setFormat(RasterImageFormat.RAW); 
      e.setWidth(myRawData.Width); 
      e.setHeight(myRawData.Height); 
      e.setBitsPerPixel(myRawData.BitsPerPixel); 
      e.setXResolution(myRawData.XResolution); 
      e.setYResolution(myRawData.YResolution); 
      e.setOffset(myRawData.Offset); 
      e.setMotorolaOrder(false); 
      e.setPhotoInterpolation(CodecsPhotoInterpolation.WHITE_IS_ZERO); 
      e.setPlanarConfiguration(CodecsPlanarConfiguration.PLANAR_FORMAT); // This value is used only if Format is 
                                                                         // RasterImageFormat.RawPackBits 
      e.setReverse(true); 
      e.setStripSize(10); 
      e.setWhiteOnBlack(false); 
      e.getPalette(); 
 
      System.out.println("Stream: " + e.getStream()); 
 
      if (myRawData.Padding) 
         e.setPad4(true); 
 
      e.setOrder(myRawData.Order); 
 
      if (myRawData.ReverseBits) 
         e.setLeastSignificantBitFirst(true); 
 
      e.setViewPerspective(myRawData.ViewPerspective); 
 
      // If image is palettized create a grayscale palette 
      if (e.getBitsPerPixel() <= 8) { 
         int colors = 1 << e.getBitsPerPixel(); 
         RasterColor[] palette = new RasterColor[colors]; 
         int[] mask = new int[colors]; 
         for (int i = 0; i < palette.length; i++) { 
            byte val = (byte) ((i * 255) / (colors - 1)); 
            palette[i] = new RasterColor(val, val, val); 
            mask[i] = val; 
         } 
 
         e.setColorMask(mask); 
         e.setPalette(palette); 
      } 
   } 
}; 
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.