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

The following are Jave code examples for showing how to use TYPE_CUSTOM of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: MemoryImageTypeConverter.java   View Source Code Vote up 6 votes
/** {@inheritDoc} */
public BufferedImage convert(Reference<BufferedImage> ref, int type)
                                                    throws ImageIOException {
  if (ref == null) throw new IllegalArgumentException();

  // NB: We don't bother clearing the ref because this method requires
  // that the source and destination images exist simultaneously.

  final BufferedImage src = ref.obj;

  // we can't create images of TYPE_CUSTOM
  if (type == BufferedImage.TYPE_CUSTOM) throw new IllegalArgumentException();

  final int w = src.getWidth();
  final int h = src.getHeight();

  final BufferedImage dst = new BufferedImage(w, h, type);

  final Graphics2D g = dst.createGraphics();
  g.drawImage(src, 0, 0, null);
  g.dispose();

  return dst;
}
 
Example 2
Project: OpenJSharp   File: ImageTypeSpecifier.java   View Source Code Vote up 6 votes
/**
 * 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
Project: jdk8u-jdk   File: ImageTypeSpecifier.java   View Source Code Vote up 6 votes
/**
 * 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 4
Project: openjdk-jdk10   File: ImageTypeSpecifier.java   View Source Code Vote up 6 votes
/**
 * Returns an {@code ImageTypeSpecifier} that encodes the
 * layout of a {@code RenderedImage} (which may be a
 * {@code BufferedImage}).
 *
 * @param image a {@code RenderedImage}.
 *
 * @return an {@code ImageTypeSpecifier} with the desired
 * characteristics.
 *
 * @exception IllegalArgumentException if {@code image} is
 * {@code null}.
 */
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 5
Project: Image-Stegano   File: ImageUtility.java   View Source Code Vote up 5 votes
/**
 * this method convert supplied image to suitable type
 * it is needed because we need bytes of array so TYPE_INT images must be
 * converted to BYTE_BGR or so
 * @param originalImage loaded from file-chooser
 * @return 
 */

public BufferedImage convertImage(BufferedImage originalImage) {
    int newImageType = originalImage.getType();
    
    /**
     * Converting int to byte since byte array is needed later to modify 
     * the image
     */
    if (newImageType == BufferedImage.TYPE_INT_RGB
            || newImageType == BufferedImage.TYPE_INT_BGR) {
        newImageType = BufferedImage.TYPE_3BYTE_BGR;
    } else if (newImageType == BufferedImage.TYPE_INT_ARGB ||
            newImageType == BufferedImage.TYPE_CUSTOM) {
        newImageType = BufferedImage.TYPE_4BYTE_ABGR;
    } else if (newImageType == BufferedImage.TYPE_INT_ARGB_PRE) {
        newImageType = BufferedImage.TYPE_4BYTE_ABGR_PRE;
    } else {
        // no need to convert original image
        return null;
    }
    BufferedImage newImage = new BufferedImage(originalImage.getWidth(), 
            originalImage.getHeight(), newImageType);
    Graphics g = newImage.getGraphics();
    g.drawImage(originalImage, 0, 0, null);
    g.dispose();
    return newImage;
}
 
Example 6
Project: CGL   File: Texture.java   View Source Code Vote up 4 votes
/**
 * Analyes the specified image and sets the proper openGLImage-values.
 * @return <code>true</code> if the image foramt has successfully detected.
 */
public boolean analyseAndSetOpenGLParameters() {
	boolean retValue = true;
	String errorString = "";

	try {
		switch(image.getType()) {
		case BufferedImage.TYPE_4BYTE_ABGR:
			openGLImageFormat= GL2.GL_RGBA;
			openGLImageType  = GL2.GL_UNSIGNED_INT_8_8_8_8; // OK!
			openGLImageInternalFormat = GL2.GL_RGBA;
			break;

		case BufferedImage.TYPE_3BYTE_BGR:
			openGLImageFormat= GL2.GL_BGR;
			openGLImageType  = GL2.GL_UNSIGNED_BYTE;
			openGLImageInternalFormat = GL2.GL_RGB;
			break;

		case BufferedImage.TYPE_BYTE_GRAY:
			openGLImageFormat= GL2.GL_LUMINANCE;
			openGLImageType  = GL2.GL_UNSIGNED_BYTE;
			openGLImageInternalFormat = GL2.GL_LUMINANCE;
			break;
		case BufferedImage.TYPE_CUSTOM:
			ColorModel colorModel = image.getColorModel();
			ColorSpace colorSpace = colorModel.getColorSpace();
			if(colorSpace.getType()==ColorSpace.TYPE_GRAY) {
				if(colorModel.hasAlpha()==true) {
					openGLImageFormat= GL2.GL_LUMINANCE_ALPHA;
					openGLImageType  = GL2.GL_UNSIGNED_BYTE;
					openGLImageInternalFormat = GL2.GL_LUMINANCE_ALPHA;
				}
				else {
					openGLImageFormat= GL2.GL_LUMINANCE;
					openGLImageType  = GL2.GL_UNSIGNED_BYTE;
					openGLImageInternalFormat = GL2.GL_LUMINANCE;
				}
			}
			else {
				errorString = "Unsupported image format."+
						"\nURL="+textureBaseURL+textureURL+"\n";
				retValue = false;
			}
			break;
		}
	}
	catch(Throwable t) {
		errorString = "Exception during image analyzing."+
				"\nURL="+textureBaseURL+textureURL+"\n"+t.getMessage();
		retValue = false;
	}

	if(!errorString.isEmpty()){
		StatusPrinter.print("ERROR", errorString, Texture.class);
	}
	return retValue;
}
 
Example 7
Project: jdk8u-jdk   File: PngOutputTypeTest.java   View Source Code Vote up 4 votes
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 8
Project: openjdk-jdk10   File: PngOutputTypeTest.java   View Source Code Vote up 4 votes
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 9
Project: OpenJSharp   File: ImageTypeSpecifier.java   View Source Code Vote up 3 votes
/**
 * 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!");
    }
}
 
Example 10
Project: jdk8u-jdk   File: ImageTypeSpecifier.java   View Source Code Vote up 3 votes
/**
 * 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!");
    }
}
 
Example 11
Project: openjdk-jdk10   File: ImageTypeSpecifier.java   View Source Code Vote up 3 votes
/**
 * 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!");
    }
}