Java Code Examples for java.awt.image.BufferedImage#TYPE_CUSTOM

The following examples show how to use java.awt.image.BufferedImage#TYPE_CUSTOM . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageTypeSpecifier.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>ImageTypeSpecifier</code> that encodes the
 * layout of a <code>RenderedImage</code> (which may be a
 * <code>BufferedImage</code>).
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @return an <code>ImageTypeSpecifier</code> with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if <code>image</code> is
 * <code>null</code>.
 */
public static
    ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }

    if (image instanceof BufferedImage) {
        int bufferedImageType = ((BufferedImage)image).getType();
        if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
            return getSpecifier(bufferedImageType);
        }
    }

    return new ImageTypeSpecifier(image);
}
 
Example 2
Source File: ImageTypeSpecifier.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>ImageTypeSpecifier</code> that encodes the
 * layout of a <code>RenderedImage</code> (which may be a
 * <code>BufferedImage</code>).
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @return an <code>ImageTypeSpecifier</code> with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if <code>image</code> is
 * <code>null</code>.
 */
public static
    ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }

    if (image instanceof BufferedImage) {
        int bufferedImageType = ((BufferedImage)image).getType();
        if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
            return getSpecifier(bufferedImageType);
        }
    }

    return new ImageTypeSpecifier(image);
}
 
Example 3
Source File: ImageManufacture.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static BufferedImage scaleImage(BufferedImage source, int width,
        int height) {
    if (width == source.getWidth() && height == source.getHeight()) {
        return source;
    }
    if (width <= 0 || height <= 0) {
        return source;
    }
    int imageType = source.getType();
    if (imageType == BufferedImage.TYPE_CUSTOM) {
        imageType = BufferedImage.TYPE_INT_ARGB;
    }
    BufferedImage target = new BufferedImage(width, height, imageType);
    Graphics2D g = target.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setBackground(CommonFxValues.TRANSPARENT);
    g.drawImage(source, 0, 0, width, height, null);
    g.dispose();
    return target;
}
 
Example 4
Source File: CameraVideo.java    From oim-fx with MIT License 6 votes vote down vote up
public BufferedImage getBufferedImage() {
	Frame capturedFrame = null;
	boolean flipChannels = false;
	BufferedImage bufferedImage = null;
	try {
		if (start) {
			if ((capturedFrame = grabber.grab()) != null) {
				int type = Java2DFrameConverter.getBufferedImageType(capturedFrame);
				double gamma = type == BufferedImage.TYPE_CUSTOM ? 1.0 : inverseGamma;
				bufferedImage = converter.getBufferedImage(capturedFrame, gamma, flipChannels, null);
			}
		}
	} catch (org.bytedeco.javacv.FrameGrabber.Exception e) {
		e.printStackTrace();
	}
	return bufferedImage;
}
 
Example 5
Source File: ImageManufacture.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static BufferedImage verticalMirrorImage(BufferedImage source) {
    try {
        int width = source.getWidth();
        int height = source.getHeight();
        int imageType = source.getType();
        if (imageType == BufferedImage.TYPE_CUSTOM) {
            imageType = BufferedImage.TYPE_INT_ARGB;
        }
        BufferedImage target = new BufferedImage(width, height, imageType);
        for (int i = 0; i < width; ++i) {
            int t = 0, b = height - 1;
            while (t < b) {
                int pt = source.getRGB(i, t);
                int pb = source.getRGB(i, b);
                target.setRGB(i, t, pb);
                target.setRGB(i, b, pt);
                t++;
                b--;
            }
        }
        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 6
Source File: ImageTypeSpecifier.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an <code>ImageTypeSpecifier</code> that encodes the
 * layout of a <code>RenderedImage</code> (which may be a
 * <code>BufferedImage</code>).
 *
 * @param image a <code>RenderedImage</code>.
 *
 * @return an <code>ImageTypeSpecifier</code> with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if <code>image</code> is
 * <code>null</code>.
 */
public static
    ImageTypeSpecifier createFromRenderedImage(RenderedImage image) {
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }

    if (image instanceof BufferedImage) {
        int bufferedImageType = ((BufferedImage)image).getType();
        if (bufferedImageType != BufferedImage.TYPE_CUSTOM) {
            return getSpecifier(bufferedImageType);
        }
    }

    return new ImageTypeSpecifier(image);
}
 
Example 7
Source File: ImageManufacture.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static BufferedImage horizontalMirrorImage(BufferedImage source) {
    try {
        int width = source.getWidth();
        int height = source.getHeight();
        int imageType = source.getType();
        if (imageType == BufferedImage.TYPE_CUSTOM) {
            imageType = BufferedImage.TYPE_INT_ARGB;
        }
        BufferedImage target = new BufferedImage(width, height, imageType);
        for (int j = 0; j < height; ++j) {
            int l = 0, r = width - 1;
            while (l < r) {
                int pl = source.getRGB(l, j);
                int pr = source.getRGB(r, j);
                target.setRGB(l, j, pr);
                target.setRGB(r, j, pl);
                l++;
                r--;
            }
        }
        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 8
Source File: ImageSaver.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Opens RGB or RGB + alpha images stored in TIFF format. */
static public final BufferedImage openTIFF(final String path, final boolean ensure_premultiplied_alpha) {
	synchronized (getPathLock(path)) {
		try {
			final BufferedImage img = openTIFF(path);

			if (ensure_premultiplied_alpha || img.getType() == BufferedImage.TYPE_INT_ARGB || img.getType() == BufferedImage.TYPE_CUSTOM) {
				// Premultiply alpha, for speed (makes a huge difference)
				final BufferedImage imgPre = new BufferedImage( img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE );
				imgPre.createGraphics().drawImage( img, 0, 0, null );
				img.flush();
				return imgPre;
			}
			return img;

		} catch (Exception e) {
			Utils.log2("openTIFF: cannot open " + path + " :\n\t" + e);
			//IJError.print(e, true);
		} finally {
			removePathLock(path);
		}
	}
	return null;
}
 
Example 9
Source File: ImageScope.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static BufferedImage indicateRectangle(BufferedImage source,
        Color color, int lineWidth, DoubleRectangle rect) {
    try {

        int width = source.getWidth();
        int height = source.getHeight();
        if (!rect.isValid(width, height)) {
            return source;
        }
        int imageType = source.getType();
        if (imageType == BufferedImage.TYPE_CUSTOM) {
            imageType = BufferedImage.TYPE_INT_ARGB;
        }
        BufferedImage target = new BufferedImage(width, height, imageType);
        Graphics2D g = target.createGraphics();
        g.drawImage(source, 0, 0, width, height, null);
        AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
        g.setComposite(ac);
        g.setColor(color);
        BasicStroke stroke = new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
                1f, new float[]{lineWidth, lineWidth}, 0f);
        g.setStroke(stroke);
        g.drawRect((int) rect.getSmallX(), (int) rect.getSmallY(), (int) rect.getWidth(), (int) rect.getHeight());
        g.dispose();
        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return source;
    }
}
 
Example 10
Source File: RasterDirectLayer.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
private BufferedImage makeOpaque(BufferedImage image) {
	if (image.getType() == BufferedImage.TYPE_CUSTOM) {
		log.warn("makeOpaque {} Unknown Image Type 0: ", getTitle());
		return image;
	}
	BufferedImage opaqueCopy = new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
	Graphics2D g1 = opaqueCopy.createGraphics();
	g1.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getOpacity()));
	g1.drawImage(image, null, 0, 0);
	g1.dispose();
	return opaqueCopy;
}
 
Example 11
Source File: ImageManufacture.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static BufferedImage cropInside(BufferedImage source,
        DoubleShape shape, Color bgColor) {
    try {
        if (shape == null || !shape.isValid()) {
            return source;
        }
        int width = source.getWidth();
        int height = source.getHeight();
        int imageType = source.getType();
        if (imageType == BufferedImage.TYPE_CUSTOM) {
            imageType = BufferedImage.TYPE_INT_ARGB;
        }
        BufferedImage target = new BufferedImage(width, height, imageType);
        int bgPixel = bgColor.getRGB();
        for (int j = 0; j < height; ++j) {
            for (int i = 0; i < width; ++i) {
                if (shape.include(i, j)) {
                    target.setRGB(i, j, bgPixel);
                } else {
                    target.setRGB(i, j, source.getRGB(i, j));
                }
            }
        }
        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return source;
    }
}
 
Example 12
Source File: ReverseBytePixelIterator.java    From pumpernickel with MIT License 4 votes vote down vote up
public int getType() {
	return BufferedImage.TYPE_CUSTOM;
}
 
Example 13
Source File: PngOutputTypeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 14
Source File: PngOutputTypeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 15
Source File: PngOutputTypeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 16
Source File: PixelsOperation.java    From MyBox with Apache License 2.0 4 votes vote down vote up
protected BufferedImage operateScope() {
    if (image == null) {
        return image;
    }
    try {
        int imageType = image.getType();
        if (imageType == BufferedImage.TYPE_CUSTOM) {
            imageType = BufferedImage.TYPE_INT_ARGB;
        }
        BufferedImage target = new BufferedImage(imageWidth, imageHeight, imageType);
        boolean isShowScope = (operationType == OperationType.ShowScope);
        boolean isWhole = (scope == null || scope.getScopeType() == ImageScope.ScopeType.All);
        boolean inScope;
        if (isDithering) {
            thisLine = new Color[imageWidth];
            nextLine = new Color[imageWidth];
            thisLineY = 0;
            thisLine[0] = new Color(image.getRGB(0, 0), true);
        }
        Color newColor;
        int pixel, transparent = 0, white = Color.WHITE.getRGB();
        for (int y = 0; y < image.getHeight(); y++) {
            for (int x = 0; x < image.getWidth(); x++) {
                pixel = image.getRGB(x, y);
                Color color = new Color(pixel, true);
                if (pixel == 0 && skipTransparent) {  // pass transparency
                    newColor = color;

                } else {

                    inScope = isWhole || scope.inScope(x, y, color);

                    if (isDithering && y == thisLineY) {
                        color = thisLine[x];
                    }
                    if (isShowScope) {
                        newColor = color;
                        if (inScope) {
                            target.setRGB(x, y, transparent);
                        } else {
                            target.setRGB(x, y, white);
                        }
                    } else {
                        if (inScope) {
                            newColor = operatePixel(target, color, x, y);

                        } else {
                            newColor = color;
                            target.setRGB(x, y, color.getRGB());
                        }
                    }
                }
                dithering(color, newColor, x, y);
            }
            if (isDithering) {
                thisLine = nextLine;
                thisLineY = y + 1;
                nextLine = new Color[imageWidth];
            }
        }
        thisLine = nextLine = null;
        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return image;
    }
}
 
Example 17
Source File: PngOutputTypeTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 18
Source File: ImageTypeSpecifier.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an {@code ImageTypeSpecifier} that encodes
 * one of the standard {@code BufferedImage} types
 * (other than {@code TYPE_CUSTOM}).
 *
 * @param bufferedImageType an int representing one of the standard
 * {@code BufferedImage} types.
 *
 * @return an {@code ImageTypeSpecifier} with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if
 * {@code bufferedImageType} is not one of the standard
 * types, or is equal to {@code TYPE_CUSTOM}.
 *
 * @see java.awt.image.BufferedImage
 * @see java.awt.image.BufferedImage#TYPE_INT_RGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
 * @see java.awt.image.BufferedImage#TYPE_INT_BGR
 * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
 * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
 * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
 * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
 * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
 */
public static
    ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
    if (bufferedImageType >= BufferedImage.TYPE_INT_RGB &&
        bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
        return getSpecifier(bufferedImageType);
    } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
        throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
    } else {
        throw new IllegalArgumentException("Invalid BufferedImage type!");
    }
}
 
Example 19
Source File: ImageTypeSpecifier.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns an {@code ImageTypeSpecifier} that encodes
 * one of the standard {@code BufferedImage} types
 * (other than {@code TYPE_CUSTOM}).
 *
 * @param bufferedImageType an int representing one of the standard
 * {@code BufferedImage} types.
 *
 * @return an {@code ImageTypeSpecifier} with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if
 * {@code bufferedImageType} is not one of the standard
 * types, or is equal to {@code TYPE_CUSTOM}.
 *
 * @see java.awt.image.BufferedImage
 * @see java.awt.image.BufferedImage#TYPE_INT_RGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
 * @see java.awt.image.BufferedImage#TYPE_INT_BGR
 * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
 * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
 * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
 * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
 * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
 */
public static
    ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
    if (bufferedImageType >= BufferedImage.TYPE_INT_RGB &&
        bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
        return getSpecifier(bufferedImageType);
    } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
        throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
    } else {
        throw new IllegalArgumentException("Invalid BufferedImage type!");
    }
}
 
Example 20
Source File: ImageTypeSpecifier.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an <code>ImageTypeSpecifier</code> that encodes
 * one of the standard <code>BufferedImage</code> types
 * (other than <code>TYPE_CUSTOM</code>).
 *
 * @param bufferedImageType an int representing one of the standard
 * <code>BufferedImage</code> types.
 *
 * @return an <code>ImageTypeSpecifier</code> with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if
 * <code>bufferedImageType</code> is not one of the standard
 * types, or is equal to <code>TYPE_CUSTOM</code>.
 *
 * @see java.awt.image.BufferedImage
 * @see java.awt.image.BufferedImage#TYPE_INT_RGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB
 * @see java.awt.image.BufferedImage#TYPE_INT_ARGB_PRE
 * @see java.awt.image.BufferedImage#TYPE_INT_BGR
 * @see java.awt.image.BufferedImage#TYPE_3BYTE_BGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR
 * @see java.awt.image.BufferedImage#TYPE_4BYTE_ABGR_PRE
 * @see java.awt.image.BufferedImage#TYPE_USHORT_565_RGB
 * @see java.awt.image.BufferedImage#TYPE_USHORT_555_RGB
 * @see java.awt.image.BufferedImage#TYPE_BYTE_GRAY
 * @see java.awt.image.BufferedImage#TYPE_USHORT_GRAY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_BINARY
 * @see java.awt.image.BufferedImage#TYPE_BYTE_INDEXED
 */
public static
    ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) {
    if (bufferedImageType >= BufferedImage.TYPE_INT_RGB &&
        bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) {
        return getSpecifier(bufferedImageType);
    } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) {
        throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!");
    } else {
        throw new IllegalArgumentException("Invalid BufferedImage type!");
    }
}