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

The following examples show how to use java.awt.image.ColorModel#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: FXGraphics2D.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts a rendered image to a {@code BufferedImage}.  This utility
 * method has come from a forum post by Jim Moore at:
 * <p>
 * <a href="http://www.jguru.com/faq/view.jsp?EID=114602">
 * http://www.jguru.com/faq/view.jsp?EID=114602</a>
 * 
 * @param img  the rendered image.
 * 
 * @return A buffered image. 
 */
private static BufferedImage convertRenderedImage(RenderedImage img) {
    if (img instanceof BufferedImage) {
        return (BufferedImage) img;
    }
    ColorModel cm = img.getColorModel();
    int width = img.getWidth();
    int height = img.getHeight();
    WritableRaster raster = cm.createCompatibleWritableRaster(width, height);
    boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
    Hashtable properties = new Hashtable();
    String[] keys = img.getPropertyNames();
    if (keys != null) {
        for (int i = 0; i < keys.length; i++) {
            properties.put(keys[i], img.getProperty(keys[i]));
        }
    }
    BufferedImage result = new BufferedImage(cm, raster, 
            isAlphaPremultiplied, properties);
    img.copyData(raster);
    return result;
}
 
Example 2
Source File: GLXGraphicsConfig.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new hidden-acceleration image of the given width and height
 * that is associated with the target Component.
 */
@Override
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr =
        model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
Example 3
Source File: ColCvtAlpha.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) {
    BufferedImage src
        = new BufferedImage(1, 10, BufferedImage.TYPE_INT_ARGB);

    // Set src pixel values
    Color pelColor = new Color(100, 100, 100, 128);
    for (int i = 0; i < 10; i++) {
        src.setRGB(0, i, pelColor.getRGB());
    }

    ColorModel cm = new ComponentColorModel
        (ColorSpace.getInstance(ColorSpace.CS_GRAY),
         new int [] {8,8}, true,
         src.getColorModel().isAlphaPremultiplied(),
         Transparency.TRANSLUCENT,
         DataBuffer.TYPE_BYTE);

    SampleModel sm = new PixelInterleavedSampleModel
        (DataBuffer.TYPE_BYTE, 100, 100, 2, 200,
         new int [] { 0, 1 });

    WritableRaster wr = Raster.createWritableRaster(sm, new Point(0,0));

    BufferedImage dst =
        new BufferedImage(cm, wr, cm.isAlphaPremultiplied(), null);
    dst = dst.getSubimage(0, 0, 1, 10);

    ColorConvertOp op = new ColorConvertOp(null);

    op.filter(src, dst);

    for (int i = 0; i < 10; i++) {
        if (((dst.getRGB(0, i) >> 24) & 0xff) != 128) {
            throw new RuntimeException(
                "Incorrect destination alpha value.");
        }
    }

}
 
Example 4
Source File: GLXGraphicsConfig.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new hidden-acceleration image of the given width and height
 * that is associated with the target Component.
 */
@Override
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr =
        model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
Example 5
Source File: GLXGraphicsConfig.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public BufferedImage createCompatibleImage(int width, int height) {
    ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
    WritableRaster
        raster = model.createCompatibleWritableRaster(width, height);
    return new BufferedImage(model, raster, model.isAlphaPremultiplied(),
                             null);
}
 
Example 6
Source File: Win32GraphicsConfig.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new managed image of the given width and height
 * that is associated with the target Component.
 */
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr =
        model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
Example 7
Source File: CGLGraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr = model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
Example 8
Source File: Win32GraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new managed image of the given width and height
 * that is associated with the target Component.
 */
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr =
        model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
Example 9
Source File: CGLGraphicsConfig.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr = model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
Example 10
Source File: Win32GraphicsConfig.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a new managed image of the given width and height
 * that is associated with the target Component.
 */
public Image createAcceleratedImage(Component target,
                                    int width, int height)
{
    ColorModel model = getColorModel(Transparency.OPAQUE);
    WritableRaster wr =
        model.createCompatibleWritableRaster(width, height);
    return new OffScreenImage(target, model, wr,
                              model.isAlphaPremultiplied());
}
 
Example 11
Source File: PageContentItem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Creates BufferedImage with Transparency.TRANSLUCENT */
private BufferedImage createBufferedImage(int width, int height) {
    if (Utilities.getOperatingSystem() == Utilities.OS_MAC) {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    }
    ColorModel model = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().
            getDefaultScreenDevice().getDefaultConfiguration().getColorModel(Transparency.TRANSLUCENT);
    BufferedImage buffImage = new BufferedImage(model,
            model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null);
    return buffImage;
}
 
Example 12
Source File: OpCompatibleImageTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private BufferedImage createCompatible(ColorModel cm, int w, int h) {
    return new BufferedImage (cm,
                              cm.createCompatibleWritableRaster(w, h),
                              cm.isAlphaPremultiplied(), null);
}
 
Example 13
Source File: OccupancyMap.java    From coordination_oru with GNU General Public License v3.0 4 votes vote down vote up
private static BufferedImage deepCopy(BufferedImage bi) {
	 ColorModel cm = bi.getColorModel();
	 boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
	 WritableRaster raster = bi.copyData(null);
	 return new BufferedImage(cm, raster, isAlphaPremultiplied, null);
}
 
Example 14
Source File: EffectUtils.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
Example 15
Source File: GraphicsUtilities.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
Example 16
Source File: GraphicsConfiguration.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 17
Source File: GraphicsConfiguration.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * 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);
}
 
Example 18
Source File: EffectUtils.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
Example 19
Source File: GraphicsUtilities.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}
 
Example 20
Source File: GraphicsUtilities.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * <p>Returns a new <code>BufferedImage</code> using the same color model
 * as the image passed as a parameter. The returned image is only compatible
 * with the image passed as a parameter. This does not mean the returned
 * image is compatible with the hardware.</p>
 *
 * @param image the reference image from which the color model of the new
 *   image is obtained
 * @return a new <code>BufferedImage</code>, compatible with the color model
 *   of <code>image</code>
 */
public static BufferedImage createColorModelCompatibleImage(BufferedImage image) {
    ColorModel cm = image.getColorModel();
    return new BufferedImage(cm,
        cm.createCompatibleWritableRaster(image.getWidth(),
                                          image.getHeight()),
        cm.isAlphaPremultiplied(), null);
}