Search in sources :

Example 11 with ColorModel

use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.

the class PngDitDepthTest method main.

public static void main(String[] args) throws IIOInvalidTreeException {
    // getting the writer for the png format
    Iterator iter = ImageIO.getImageWritersByFormatName("png");
    ImageWriter writer = (ImageWriter) iter.next();
    // creating a color model
    ColorModel colorModel = ColorModel.getRGBdefault();
    // creating a sample model
    SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);
    // creating a default metadata object
    IIOMetadata metaData = writer.getDefaultImageMetadata(new ImageTypeSpecifier(colorModel, sampleModel), null);
    String formatName = metaData.getNativeMetadataFormatName();
    // first call
    Node metaDataNode = metaData.getAsTree(formatName);
    try {
        metaData.setFromTree(formatName, metaDataNode);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    // second call (bitdepht is already set to an invalid value)
    metaDataNode = metaData.getAsTree(formatName);
    metaData.setFromTree(formatName, metaDataNode);
}
Also used : IIOMetadata(javax.imageio.metadata.IIOMetadata) SampleModel(java.awt.image.SampleModel) ColorModel(java.awt.image.ColorModel) Node(org.w3c.dom.Node) Iterator(java.util.Iterator) ImageWriter(javax.imageio.ImageWriter) ImageTypeSpecifier(javax.imageio.ImageTypeSpecifier) IIOInvalidTreeException(javax.imageio.metadata.IIOInvalidTreeException)

Example 12 with ColorModel

use of java.awt.image.ColorModel in project intellij-community by JetBrains.

the class ImagePreviewComponent method createLabel.

@NotNull
private static JLabel createLabel(@NotNull final BufferedImage image, long imageFileSize) {
    final int width = image.getWidth();
    final int height = image.getHeight();
    final ColorModel colorModel = image.getColorModel();
    final int i = colorModel.getPixelSize();
    return new JLabel(String.format("%dx%d, %dbpp, %s", width, height, i, StringUtil.formatFileSize(imageFileSize)));
}
Also used : ColorModel(java.awt.image.ColorModel) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with ColorModel

use of java.awt.image.ColorModel in project scriptographer by scriptographer.

the class Raster method createCompatibleImage.

/**
	 * @jshide
	 */
public BufferedImage createCompatibleImage(int width, int height) {
    ColorModel cm = getColorModel();
    WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
    return new BufferedImage(cm, raster, false, null);
}
Also used : ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage)

Example 14 with ColorModel

use of java.awt.image.ColorModel in project scriptographer by scriptographer.

the class Raster method getCompatibleType.

/**
	 * @jshide
	 */
public static ColorType getCompatibleType(Image image) {
    if (image instanceof BufferedImage) {
        ColorModel cm = ((BufferedImage) image).getColorModel();
        int type = cm.getColorSpace().getType();
        boolean alpha = cm.hasAlpha();
        if (type == ColorSpace.TYPE_RGB) {
            return alpha ? ColorType.ARGB : ColorType.RGB;
        } else if (type == ColorSpace.TYPE_CMYK) {
            return alpha ? ColorType.ACMYK : ColorType.CMYK;
        }
        if (type == ColorSpace.TYPE_GRAY) {
            return alpha ? ColorType.AGRAY : ColorType.GRAY;
        }
    }
    return null;
}
Also used : ComponentColorModel(java.awt.image.ComponentColorModel) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) BufferedImage(java.awt.image.BufferedImage)

Example 15 with ColorModel

use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.

the class GraphicsConfiguration method createCompatibleImage.

/**
     * Returns a {@link BufferedImage} with a data layout and color model
     * compatible with this <code>GraphicsConfiguration</code>.  This
     * method has nothing to do with memory-mapping
     * a device.  The returned <code>BufferedImage</code> has
     * a layout and color model that is closest to this native device
     * configuration and can therefore be optimally blitted to this
     * device.
     * @param width the width of the returned <code>BufferedImage</code>
     * @param height the height of the returned <code>BufferedImage</code>
     * @return a <code>BufferedImage</code> whose data layout and color
     * model is compatible with this <code>GraphicsConfiguration</code>.
     */
public BufferedImage createCompatibleImage(int width, int height) {
    ColorModel model = getColorModel();
    WritableRaster raster = model.createCompatibleWritableRaster(width, height);
    return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null);
}
Also used : ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ColorModel (java.awt.image.ColorModel)104 IndexColorModel (java.awt.image.IndexColorModel)44 BufferedImage (java.awt.image.BufferedImage)43 WritableRaster (java.awt.image.WritableRaster)34 DirectColorModel (java.awt.image.DirectColorModel)31 ComponentColorModel (java.awt.image.ComponentColorModel)24 SampleModel (java.awt.image.SampleModel)17 Raster (java.awt.image.Raster)16 ColorSpace (java.awt.color.ColorSpace)12 Graphics2D (java.awt.Graphics2D)11 Rectangle (java.awt.Rectangle)9 SurfaceData (sun.java2d.SurfaceData)9 Point (java.awt.Point)8 ComponentSampleModel (java.awt.image.ComponentSampleModel)8 ImageTypeSpecifier (javax.imageio.ImageTypeSpecifier)7 PackedColorModel (java.awt.image.PackedColorModel)6 Component (java.awt.Component)4 Paint (java.awt.Paint)4 RenderingHints (java.awt.RenderingHints)4 AffineTransform (java.awt.geom.AffineTransform)4