LoadInformation Event (original) (raw)

Summary

Occurs during loading of a file for which LEADTOOLS cannot recognize the format.

Syntax

synchronized public void addLoadInformationListener(CodecsLoadInformationListener listener) synchronized public void removeLoadInformationListener(CodecsLoadInformationListener listener)

public: event EventHandler<CodecsLoadInformationEventArgs^>^ LoadInformation

def LoadInformation(sender,e): # sender: RasterCodecs e: CodecsLoadInformationEventArgs 

Event Data

The event handler receives an argument of type CodecsLoadInformationEventArgs containing data related to this event. The following CodecsLoadInformationEventArgs properties provide information specific to this event.

Property Description
BitsPerPixel Gets or sets the bits per pixel of the image data in the file.
Format Gets the image file format.
Height Gets or sets the image height in pixels.
LeastSignificantBitFirst Gets or sets a value specifying whether the image data was saved with least significant bit first or last.
MotorolaOrder Gets or sets a value that determines whether image data is in Motorola byte order.
Offset Gets or sets the position of the first byte of image data.
Order Gets or sets the byte order for the load process.
Pad4 Gets or sets a value indicating whether the image data was saved padded to 4-byte boundary.
PhotoInterpolation Gets or sets the photometric interpolation for the load process.
PlanarConfiguration Gets or sets the planar configuration.
Reverse Gets or sets a value that determines whether each line is reversed (mirrored).
Signed Gets or sets a value that determines whether the image data is signed.
Stream Gets the stream used by the load process.
StripSize Gets or sets the size of the data strip before it is decompressed.
ViewPerspective Gets or sets the view perspective for the load process.
WhiteOnBlack Gets or sets a value that determines if the image is black-on-white or white on black.
Width Gets or sets the image width in pixels.
XResolution Gets or sets the horizontal resolution for rendering the image, specified in dots per inch.
YResolution Gets or sets the vertical resolution for rendering the image, specified in dots per inch.

Example

This example demonstrates saving and loading raw/headerless image files.

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:\LEADTOOLS22\Resources\Images"; }

Leadtools.Codecs Assembly

CompactFile(Stream,Stream,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(Stream,Stream,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

CompactFile(string,string,int,int,bool,int,int,bool,int,CodecsSavePageMode,bool,bool) Method

CompactFile(string,string,int,int,bool,long,int,bool,long,CodecsSavePageMode,bool,bool,bool) Method

StartCompress(int,int,int,RasterByteOrder,RasterViewPerspective,int,byte[],int,int,CodecsCompression,CodecsCompressDataCallback) Method