Class EmfDecoder

java.lang.Object
com.idrsolutions.image.JDeliImage
com.idrsolutions.image.emf.EmfDecoder
All Implemented Interfaces:
com.idrsolutions.image.Decoder

public class EmfDecoder extends com.idrsolutions.image.JDeliImage implements com.idrsolutions.image.Decoder
Class reads EMF images as BufferedImage Make NO assumptions about the BufferedImage type returned as this may change

Example 1 (Using raw byte data):


 EmfDecoder decoder = new EmfDecoder();
 BufferedImage decodedImage = decoder.read(emfBytes);
 

Example 2 (Using a File):


 File enfFile = new File("C:\\path\\to\\file\\image.emf");
 EmfDecoder decoder = new EmfDecoder();
 BufferedImage decodedImage = decoder.read(emfFile);
 
  • Field Summary

    Fields inherited from class com.idrsolutions.image.JDeliImage

    bb
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    getCommand(int command)
    Returns the lower case name of an EMF record type, for debugging and logging.
    boolean
    isReadable(byte[] emfRawData)
    Checks whether the emf image data can be decoded, by validating its structure without decoding the pixels
    boolean
    isReadable(File imageFile)
    Checks whether the emf image file can be decoded, by validating its structure without decoding the pixels
    read(byte[] data)
    Decodes and returns the WMF image as a BufferedImage from bytes
    read(File file)
    Decodes and returns the WMF file as a BufferedImage from a file
    readDimension(byte[] emfRawData)
    Decodes and returns the width and height of emf image
    Decodes and returns the width and height of emf image
    static void
    toSVG(File emfFile, File svgOutputFile)
    Converts an EMF file to SVG and writes it to a file.
    static void
    toSVG(InputStream emfInputStream, OutputStream svgOutputFile)
    Converts EMF data from a stream to SVG and writes it to a stream.

    Methods inherited from class com.idrsolutions.image.JDeliImage

    optimiseImage

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.idrsolutions.image.Decoder

    getImageCount, getImageCount, readEmbeddedThumbnail, readEmbeddedThumbnail, readImageAt, readImageAt, readImageSpecificMetaData, readImageSpecificMetaData, setMetadata
  • Constructor Details

    • EmfDecoder

      public EmfDecoder()
  • Method Details

    • getCommand

      public static String getCommand(int command)
      Returns the lower case name of an EMF record type, for debugging and logging.
      Parameters:
      command - EMF record type value
      Returns:
      record name, such as "polygon", or "unknown type " followed by the value in hex if the type is not recognised
    • read

      public BufferedImage read(File file) throws IOException
      Decodes and returns the WMF file as a BufferedImage from a file
      Specified by:
      read in interface com.idrsolutions.image.Decoder
      Parameters:
      file - input image file to be decoded
      Returns:
      BufferedImage decoded image
      Throws:
      IOException - if an error occurs in reading image
    • read

      public BufferedImage read(byte[] data) throws IOException
      Decodes and returns the WMF image as a BufferedImage from bytes
      Specified by:
      read in interface com.idrsolutions.image.Decoder
      Parameters:
      data - byte[] containing the WMF data to be decoded
      Returns:
      BufferedImage The decoded image
      Throws:
      IOException - if an error occurs in reading image
    • readDimension

      public Rectangle readDimension(File file) throws Exception
      Decodes and returns the width and height of emf image
      Specified by:
      readDimension in interface com.idrsolutions.image.Decoder
      Parameters:
      file - image image contained in raw data if present
      Returns:
      width and height of image
      Throws:
      Exception - if problem reading image
    • readDimension

      public Rectangle readDimension(byte[] emfRawData) throws Exception
      Decodes and returns the width and height of emf image
      Specified by:
      readDimension in interface com.idrsolutions.image.Decoder
      Parameters:
      emfRawData - image image contained in raw data if present
      Returns:
      Rectangle width and height of image
      Throws:
      Exception - if problem reading image
    • isReadable

      public boolean isReadable(byte[] emfRawData) throws Exception
      Checks whether the emf image data can be decoded, by validating its structure without decoding the pixels
      Specified by:
      isReadable in interface com.idrsolutions.image.Decoder
      Parameters:
      emfRawData - emf image data
      Returns:
      true if the image can be decoded
      Throws:
      Exception - if problem reading image
    • isReadable

      public boolean isReadable(File imageFile) throws Exception
      Checks whether the emf image file can be decoded, by validating its structure without decoding the pixels
      Specified by:
      isReadable in interface com.idrsolutions.image.Decoder
      Parameters:
      imageFile - emf image file
      Returns:
      true if the image can be decoded
      Throws:
      Exception - if problem reading image
    • toSVG

      public static void toSVG(File emfFile, File svgOutputFile) throws IOException
      Converts an EMF file to SVG and writes it to a file.
      Parameters:
      emfFile - EMF file to convert
      svgOutputFile - file to write the SVG to
      Throws:
      IOException - if the EMF file cannot be read or the SVG cannot be written
    • toSVG

      public static void toSVG(InputStream emfInputStream, OutputStream svgOutputFile) throws IOException
      Converts EMF data from a stream to SVG and writes it to a stream. The data is copied to a temporary file, which is deleted afterwards. Both streams are closed by this method.
      Parameters:
      emfInputStream - stream containing the EMF data
      svgOutputFile - stream to write the SVG to
      Throws:
      IOException - if the EMF data cannot be read or the SVG cannot be written