Example usage for java.awt.image ColorModel isAlphaPremultiplied

List of usage examples for java.awt.image ColorModel isAlphaPremultiplied

Introduction

In this page you can find the example usage for java.awt.image ColorModel isAlphaPremultiplied.

Prototype

boolean isAlphaPremultiplied

To view the source code for java.awt.image ColorModel isAlphaPremultiplied.

Click Source Link

Usage

From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfGraphics2D.java

/**
 * @noinspection UseOfObsoleteCollectionType
 * @see Graphics2D#drawRenderedImage(RenderedImage, AffineTransform)
 */// w ww. jav a2s  .  c  o m
@Override
public void drawRenderedImage(final RenderedImage img, final AffineTransform xform) {
    final BufferedImage image;
    if (img instanceof BufferedImage) {
        image = (BufferedImage) img;
    } else {
        final ColorModel cm = img.getColorModel();
        final int width = img.getWidth();
        final int height = img.getHeight();
        final WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
        final boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
        final Hashtable properties = new Hashtable();
        final String[] keys = img.getPropertyNames();
        if (keys != null) {
            final int keyCount = keys.length;
            for (int i = 0; i < keyCount; i++) {
                properties.put(keys[i], img.getProperty(keys[i]));
            }
        }
        final BufferedImage result = new BufferedImage(cm, raster, isAlphaPremultiplied, properties);
        img.copyData(raster);
        image = result;
    }
    drawImage(image, xform, null);
}

From source file:org.sbs.util.ImageCompress.java

/**
 * ?/*from w w w.j ava2 s.c o m*/
 * 
 * @param source
 * @param targetW
 * @param targetH
 * @return
 */
public BufferedImage resize(BufferedImage source, int targetW, int targetH) {
    // targetWtargetH
    int desH = 0;
    int type = source.getType();
    BufferedImage target = null;
    double sx = (double) targetW / source.getWidth();
    double sy = sx;
    desH = (int) (sx * source.getHeight());
    if (desH < targetH) {
        desH = targetH;
        sy = (double) 61 / source.getHeight();
    }
    if (type == BufferedImage.TYPE_CUSTOM) { // handmade
        ColorModel cm = source.getColorModel();
        WritableRaster raster = cm.createCompatibleWritableRaster(targetW, desH);
        boolean alphaPremultiplied = cm.isAlphaPremultiplied();
        target = new BufferedImage(cm, raster, alphaPremultiplied, null);
    } else
        target = new BufferedImage(targetW, desH, type);
    Graphics2D g = target.createGraphics();
    // smoother than exlax:
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy));
    g.dispose();
    return target;
}

From source file:pl.dp.bz.poid.fouriertest.FourierProc.java

public static BufferedImage copyImage(BufferedImage bi) {
    ColorModel cm = bi.getColorModel();
    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    WritableRaster raster = bi.copyData(null);
    return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}