Class ImageUtils

java.lang.Object
org.apache.poi.ss.util.ImageUtils

public class ImageUtils extends Object
Author:
Yegor Kozlov
  • Field Details

  • Constructor Details

    • ImageUtils

      public ImageUtils()
  • Method Details

    • getImageDimension

      public static Dimension getImageDimension(InputStream is, int type)
      Return the dimension of this image
      Parameters:
      is - the stream containing the image data
      type - type of the picture: Workbook.PICTURE_TYPE_JPEG, Workbook.PICTURE_TYPE_PNG or Workbook.PICTURE_TYPE_DIB
      Returns:
      image dimension in pixels
    • getResolution

      public static int[] getResolution(ImageReader r) throws IOException
      The metadata of PNG and JPEG can contain the width of a pixel in millimeters. Return the the "effective" dpi calculated as 25.4/HorizontalPixelSize and 25.4/VerticalPixelSize. Where 25.4 is the number of mm in inch.
      Returns:
      array of two elements: {horisontalPdi, verticalDpi}. {96, 96} is the default.
      Throws:
      IOException
    • setPreferredSize

      public static Dimension setPreferredSize(Picture picture, double scaleX, double scaleY)
      Calculate and set the preferred size (anchor) for this picture.
      Parameters:
      scaleX - the amount by which image width is multiplied relative to the original width.
      scaleY - the amount by which image height is multiplied relative to the original height.
      Returns:
      the new Dimensions of the scaled picture in EMUs
    • getDimensionFromAnchor

      public static Dimension getDimensionFromAnchor(Picture picture)
      Calculates the dimensions in EMUs for the anchor of the given picture
      Parameters:
      picture - the picture containing the anchor
      Returns:
      the dimensions in EMUs
    • getRowHeightInPixels

      public static double getRowHeightInPixels(Sheet sheet, int rowNum)