Class MagickUtil

java.lang.Object
com.twelvemonkeys.image.MagickUtil

public final class MagickUtil extends Object
Utility for converting JMagick MagickImages to standard Java BufferedImages and back.

NOTE: This class is considered an implementation detail and not part of the public API. This class is subject to change without further notice. You have been warned. :-)

Version:
$Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/MagickUtil.java#4 $
Author:
Harald Kuhr
  • Method Details

    • toBuffered

      public static BufferedImage toBuffered(magick.MagickImage pImage) throws magick.MagickException
      Converts a MagickImage to a BufferedImage.

      The conversion depends on pImage's ImageType:

      ImageType.BilevelType
      BufferedImage of type TYPE_BYTE_BINARY
      ImageType.GrayscaleType
      BufferedImage of type TYPE_BYTE_GRAY
      ImageType.GrayscaleMatteType
      BufferedImage of type TYPE_USHORT_GRAY
      ImageType.PaletteType
      BufferedImage of type TYPE_BYTE_BINARY (for images with a palette of <= 16 colors) or TYPE_BYTE_INDEXED
      ImageType.PaletteMatteType
      BufferedImage of type TYPE_BYTE_BINARY (for images with a palette of <= 16 colors) or TYPE_BYTE_INDEXED
      ImageType.TrueColorType
      BufferedImage of type TYPE_3BYTE_BGR
      ImageType.TrueColorPaletteType
      BufferedImage of type TYPE_4BYTE_ABGR
      Parameters:
      pImage - the original MagickImage
      Returns:
      a new BufferedImage
      Throws:
      IllegalArgumentException - if pImage is null or if the ImageType is not one mentioned above.
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • toMagick

      public static magick.MagickImage toMagick(BufferedImage pImage) throws magick.MagickException
      Converts a BufferedImage to a MagickImage.

      The conversion depends on pImage's ColorModel:

      IndexColorModel with 1 bit b/w
      MagickImage of type ImageType.BilevelType
      IndexColorModel > 1 bit,
      MagickImage of type ImageType.PaletteType or MagickImage of type ImageType.PaletteMatteType depending on ColorModel.getAlpha()
      ColorModel.getColorSpace().getType() == ColorSpace.TYPE_GRAY
      MagickImage of type ImageType.GrayscaleType or MagickImage of type ImageType.GrayscaleMatteType depending on ColorModel.getAlpha()
      ColorModel.getColorSpace().getType() == ColorSpace.TYPE_RGB
      MagickImage of type ImageType.TrueColorType or MagickImage of type ImageType.TrueColorPaletteType
      Parameters:
      pImage - the original BufferedImage
      Returns:
      a new MagickImage
      Throws:
      IllegalArgumentException - if pImage is null or if the ColorModel is not one mentioned above.
      magick.MagickException - if an exception occurs during conversion
      See Also:
    • createIndexColorModel

      public static IndexColorModel createIndexColorModel(magick.PixelPacket[] pColormap, boolean pAlpha)
      Creates an IndexColorModel from an array of PixelPackets.
      Parameters:
      pColormap - the original colormap as a PixelPacket array
      pAlpha - keep alpha channel
      Returns:
      a new IndexColorModel