Java Code Examples for java.awt.image.IndexColorModel#isAlphaPremultiplied()

The following examples show how to use java.awt.image.IndexColorModel#isAlphaPremultiplied() . 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: ICMColorDataTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void makeImage() {
    int scanLineBytes = WIDTH / PIXELS_IN_BYTE;
    if ((WIDTH & (PIXELS_IN_BYTE - 1)) != 0) {
        // Make sure all the pixels in a scan line fit
        scanLineBytes += 1;
    }

    byte[]     bits    = new byte[scanLineBytes * HEIGHT];
    DataBuffer dataBuf = new DataBufferByte(bits, bits.length, 0);
    SampleModel sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                              WIDTH, HEIGHT, BITS_PER_PIXEL);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuf, null);
    IndexColorModel indexModel = new IndexColorModel(2, 2, RED, GREEN, BLUE);
    BufferedImage bufImage = new BufferedImage(indexModel, raster,
                                               indexModel.isAlphaPremultiplied(), null);

    Graphics g = bufImage.getGraphics();
    g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
    g.dispose();
}
 
Example 2
Source File: ICMColorDataTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void makeImage() {
    int scanLineBytes = WIDTH / PIXELS_IN_BYTE;
    if ((WIDTH & (PIXELS_IN_BYTE - 1)) != 0) {
        // Make sure all the pixels in a scan line fit
        scanLineBytes += 1;
    }

    byte[]     bits    = new byte[scanLineBytes * HEIGHT];
    DataBuffer dataBuf = new DataBufferByte(bits, bits.length, 0);
    SampleModel sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                              WIDTH, HEIGHT, BITS_PER_PIXEL);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuf, null);
    IndexColorModel indexModel = new IndexColorModel(2, 2, RED, GREEN, BLUE);
    BufferedImage bufImage = new BufferedImage(indexModel, raster,
                                               indexModel.isAlphaPremultiplied(), null);

    Graphics g = bufImage.getGraphics();
    g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
    g.dispose();
}
 
Example 3
Source File: ICMColorDataTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static void makeImage() {
    int scanLineBytes = WIDTH / PIXELS_IN_BYTE;
    if ((WIDTH & (PIXELS_IN_BYTE - 1)) != 0) {
        // Make sure all the pixels in a scan line fit
        scanLineBytes += 1;
    }

    byte[]     bits    = new byte[scanLineBytes * HEIGHT];
    DataBuffer dataBuf = new DataBufferByte(bits, bits.length, 0);
    SampleModel sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                              WIDTH, HEIGHT, BITS_PER_PIXEL);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuf, null);
    IndexColorModel indexModel = new IndexColorModel(2, 2, RED, GREEN, BLUE);
    BufferedImage bufImage = new BufferedImage(indexModel, raster,
                                               indexModel.isAlphaPremultiplied(), null);

    Graphics g = bufImage.getGraphics();
    g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
    g.dispose();
}
 
Example 4
Source File: HeadlessIndexColorModel.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String args[]) {
    IndexColorModel cm =
            new IndexColorModel(8, 1, new byte[]{(byte) 128}, new byte[]{(byte) 128}, new byte[]{(byte) 128});
    cm.getTransparency();
    cm.getComponentSize();
    cm.isAlphaPremultiplied();
    cm.hasAlpha();
    cm.isAlphaPremultiplied();
    cm.getTransferType();
    cm.getPixelSize();
    cm.getComponentSize();
    cm.getNumComponents();
    cm.getNumColorComponents();
    cm.getRed(20);
    cm.getGreen(20);
    cm.getBlue(20);
    cm.getAlpha(20);
    cm.getRGB(20);
    cm.isAlphaPremultiplied();
}
 
Example 5
Source File: ICMColorDataTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void makeImage() {
    int scanLineBytes = WIDTH / PIXELS_IN_BYTE;
    if ((WIDTH & (PIXELS_IN_BYTE - 1)) != 0) {
        // Make sure all the pixels in a scan line fit
        scanLineBytes += 1;
    }

    byte[]     bits    = new byte[scanLineBytes * HEIGHT];
    DataBuffer dataBuf = new DataBufferByte(bits, bits.length, 0);
    SampleModel sampleModel = new MultiPixelPackedSampleModel(DataBuffer.TYPE_BYTE,
                                                              WIDTH, HEIGHT, BITS_PER_PIXEL);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, dataBuf, null);
    IndexColorModel indexModel = new IndexColorModel(2, 2, RED, GREEN, BLUE);
    BufferedImage bufImage = new BufferedImage(indexModel, raster,
                                               indexModel.isAlphaPremultiplied(), null);

    Graphics g = bufImage.getGraphics();
    g.drawRect(0, 0, WIDTH - 1, HEIGHT - 1);
    g.dispose();
}
 
Example 6
Source File: WbmpImageParser.java    From commons-imaging with Apache License 2.0 5 votes vote down vote up
private BufferedImage readImage(final WbmpHeader wbmpHeader, final InputStream is)
        throws IOException {
    final int rowLength = (wbmpHeader.width + 7) / 8;
    final byte[] image = readBytes("Pixels", is,
            rowLength * wbmpHeader.height, "Error reading image pixels");
    final DataBufferByte dataBuffer = new DataBufferByte(image, image.length);
    final WritableRaster raster = Raster.createPackedRaster(dataBuffer,
            wbmpHeader.width, wbmpHeader.height, 1, null);
    final int[] palette = { 0x000000, 0xffffff };
    final IndexColorModel colorModel = new IndexColorModel(1, 2, palette, 0,
            false, -1, DataBuffer.TYPE_BYTE);
    return new BufferedImage(colorModel, raster,
            colorModel.isAlphaPremultiplied(), new Properties());
}