ImageGear v26.5 - Updated
Developer Guide / How to Work with ... / Common Operations / Detect Image Format
In This Topic
    Detect Image Format
    In This Topic

    Image formats are detected with ImGearFileFormats.Detect(Stream) after configuring ImageGear's global file format list, managed with ImGearFileFilters.

    File formats are checked in the order in which they occur in this list. Re-ordering this list allows you to customize the format detection process. Raster Color and Grayscale formats are added automatically when ImGearCommonFormats.Initialize() is called. Other formats, such as PDF, Email and Office, must be added explicitly with ImGearFileFormats.Filters.Add(IImGearFormat) followed by assembly initialization as required. If you do not need a particular format, it can be omitted or removed from the list.

    See also Supported Formats and Compressions.

    Detect Raster Formats

    To allow ImGearFileFormats.Detect(Stream) to identify Color and Grayscale Raster formats, use ImGearCommonFormats.Initialize() to automatically add these formats to the ImGearFileFilters file format list.

    Our DetectImageFormat sample on GitHub demonstrates how to detect the format of the raster image.

    To detect the Email format, you have to add MSG and EML format filters. See ImGearFileFormats.Filters.Add(), ImGearEmail.CreateMSGFormat(), and ImGearEmail.CreateEMLFormat().

    To detect the PDF format, you have to add PDF and PS format filters, and initialize the PDF. See ImGearPDF.CreatePDFFormat(), ImGearPDF.CreatePSFormat(), and ImGearPDF.Initialize().