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);
}
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)));
}
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);
}
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;
}
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);
}
Aggregations