Java Code Examples for java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE

The following are Jave code examples for showing how to use TYPE_INT_ARGB_PRE of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: ColConvTest.java   View Source Code Vote up 6 votes
static String getImageTypeName(int type) {
    switch(type) {
        case BufferedImage.TYPE_INT_ARGB:
            return "TYPE_INT_ARGB";
        case BufferedImage.TYPE_INT_RGB:
            return "TYPE_INT_RGB";
        case BufferedImage.TYPE_INT_BGR:
            return "TYPE_INT_BGR";
        case BufferedImage.TYPE_INT_ARGB_PRE:
            return "TYPE_INT_ARGB_PRE";
        case BufferedImage.TYPE_3BYTE_BGR:
            return "TYPE_3BYTE_BGR";
        case BufferedImage.TYPE_4BYTE_ABGR:
            return "TYPE_4BYTE_ABGR";
        case BufferedImage.TYPE_4BYTE_ABGR_PRE:
            return "TYPE_4BYTE_ABGR_PRE";
        case BufferedImage.TYPE_BYTE_BINARY:
            return "TYPE_BYTE_BINARY";
        case BufferedImage.TYPE_BYTE_GRAY:
            return "TYPE_BYTE_GRAY";
        case BufferedImage.TYPE_BYTE_INDEXED:
            return "TYPE_BYTE_INDEXED";
        case BufferedImage.TYPE_USHORT_555_RGB:
            return "TYPE_USHORT_555_RGB";
        case BufferedImage.TYPE_USHORT_565_RGB:
            return "TYPE_USHORT_565_RGB";
        case BufferedImage.TYPE_USHORT_GRAY:
            return "TYPE_USHORT_GRAY";
    }
    return "UNKNOWN";
}
 
Example 2
Project: openjdk-jdk10   File: AquaInternalFrameDockIconUI.java   View Source Code Vote up 6 votes
void updateIcon() {
    int width = fFrame.getWidth();
    int height = fFrame.getHeight();

    // Protect us from unsized frames, like in JCK test DefaultDesktopManager2008
    if (width <= 0 || height <= 0) {
        width = 128;
        height = 128;
    }

    final Image fImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    final Graphics g = fImage.getGraphics();
    fFrame.paint(g);
    g.dispose();

    final float scale = (float)fDesktopIcon.getWidth() / (float)Math.max(width, height) * 0.89f;
    // Sending in -1 for width xor height causes it to maintain aspect ratio
    setIcon(new ImageIcon(fImage.getScaledInstance((int)(width * scale), -1, Image.SCALE_SMOOTH)));
}
 
Example 3
Project: openjdk-jdk10   File: WTaskbarPeer.java   View Source Code Vote up 6 votes
private static int[] imageToArray(Image image) {
    if (image == null) {
        return null;
    }

    int w = image.getWidth(null);
    int h = image.getHeight(null);

    if (w < 0 || h < 0) {
        return null;
    }

    BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D g2 = bimg.createGraphics();
    g2.setComposite(AlphaComposite.Src);
    g2.drawImage(image, 0, 0, null);
    g2.dispose();

    return ((DataBufferInt) bimg.getRaster().getDataBuffer()).getData();
}
 
Example 4
Project: jdk8u-jdk   File: ImageRepresentation.java   View Source Code Vote up 5 votes
void createBufferedImage() {
    // REMIND:  Be careful!  Is this called everytime there is a
    // startProduction?  We only want to call it if it is new or
    // there is an error
    isDefaultBI = false;
    try {
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster,
                             cmodel.isAlphaPremultiplied(), null);
    } catch (Exception e) {
        // Create a default image
        cmodel = ColorModel.getRGBdefault();
        biRaster = cmodel.createCompatibleWritableRaster(width, height);
        bimage = createImage(cmodel, biRaster, false, null);
    }
    int type = bimage.getType();

    if ((cmodel == ColorModel.getRGBdefault()) ||
           (type == BufferedImage.TYPE_INT_RGB) ||
           (type == BufferedImage.TYPE_INT_ARGB_PRE)) {
        isDefaultBI = true;
    }
    else if (cmodel instanceof DirectColorModel) {
        DirectColorModel dcm = (DirectColorModel) cmodel;
        if (dcm.getRedMask() == 0xff0000 &&
            dcm.getGreenMask() == 0xff00 &&
            dcm.getBlueMask()  == 0xff) {
            isDefaultBI = true;
        }
    }
}
 
Example 5
Project: EcoSystem-Official   File: IconLoader.java   View Source Code Vote up 5 votes
private static ByteBuffer loadInstance(BufferedImage image, int dimension) {
    BufferedImage scaledIcon = new BufferedImage(dimension, dimension, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics2D g = scaledIcon.createGraphics();
    double ratio = getIconRatio(image, scaledIcon);
    double width = image.getWidth() * ratio;
    double height = image.getHeight() * ratio;
    g.drawImage(image, (int) ((scaledIcon.getWidth() - width) / 2), (int) ((scaledIcon.getHeight() - height) / 2),
            (int) (width), (int) (height), null);
    g.dispose();

    return convertToByteBuffer(scaledIcon);
}
 
Example 6
Project: incubator-netbeans   File: ImageUtilities.java   View Source Code Vote up 5 votes
/** Creates BufferedImage with Transparency.TRANSLUCENT */
static final java.awt.image.BufferedImage createBufferedImage(int width, int height) {
    if (Utilities.isMac()) {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    }

    ColorModel model = colorModel(java.awt.Transparency.TRANSLUCENT);
    java.awt.image.BufferedImage buffImage = new java.awt.image.BufferedImage(
            model, model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null
        );

    return buffImage;
}
 
Example 7
Project: incubator-netbeans   File: ChicletWrapper.java   View Source Code Vote up 5 votes
private BufferedImage createImage() {
    BufferedImage img = new BufferedImage (bounds.width, bounds.height,
        BufferedImage.TYPE_INT_ARGB_PRE);
    chiclet.setNotch(rightNotch, leftNotch);
    chiclet.setArcs (arcs[0], arcs[1], arcs[2], arcs[3]);
    chiclet.setBounds (bounds.x, bounds.y, bounds.width, bounds.height);
    chiclet.setAllowVertical(allowVertical);
    chiclet.setState (state);
    Graphics g = img.getGraphics();
    g.translate (-bounds.x, -bounds.y);
    ColorUtil.setupAntialiasing(g);
    chiclet.draw((Graphics2D)g);
    g.translate (bounds.x, bounds.y);
    return img;
}
 
Example 8
Project: incubator-netbeans   File: UINodeTest.java   View Source Code Vote up 5 votes
static final java.awt.image.BufferedImage createBufferedImage(int width, int height) {
    if (Utilities.isMac()) {
        return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    }

    ColorModel model = colorModel(java.awt.Transparency.TRANSLUCENT);
    java.awt.image.BufferedImage buffImage = new java.awt.image.BufferedImage(
            model, model.createCompatibleWritableRaster(width, height), model.isAlphaPremultiplied(), null
        );

    return buffImage;
}
 
Example 9
Project: jdk8u-jdk   File: OGLBlitLoops.java   View Source Code Vote up 5 votes
private synchronized void complexClipBlit(SurfaceData src, SurfaceData dst,
                                          Composite comp, Region clip,
                                          int sx, int sy, int dx, int dy,
                                          int w, int h) {
    SurfaceData cachedSrc = null;
    if (srcTmp != null) {
        // use cached intermediate surface, if available
        cachedSrc = srcTmp.get();
    }

    // We can convert argb_pre data from OpenGL surface in two places:
    // - During OpenGL surface -> SW blit
    // - During SW -> SW blit
    // The first one is faster when we use opaque OGL surface, because in
    // this case we simply skip conversion and use color components as is.
    // Because of this we align intermediate buffer type with type of
    // destination not source.
    final int type = typeval == OGLSurfaceData.PF_INT_ARGB_PRE ?
                     BufferedImage.TYPE_INT_ARGB_PRE :
                     BufferedImage.TYPE_INT_ARGB;

    src = convertFrom(this, src, sx, sy, w, h, cachedSrc, type);

    // copy intermediate SW to destination SW using complex clip
    final Blit performop = Blit.getFromCache(src.getSurfaceType(),
                                             CompositeType.SrcNoEa,
                                             dst.getSurfaceType());
    performop.Blit(src, dst, comp, clip, 0, 0, dx, dy, w, h);

    if (src != cachedSrc) {
        // cache the intermediate surface
        srcTmp = new WeakReference<>(src);
    }
}
 
Example 10
Project: LowPolyWater   File: IconLoader.java   View Source Code Vote up 5 votes
private static ByteBuffer loadInstance(BufferedImage image, int dimension) {
	BufferedImage scaledIcon = new BufferedImage(dimension, dimension, BufferedImage.TYPE_INT_ARGB_PRE);
	Graphics2D g = scaledIcon.createGraphics();
	double ratio = getIconRatio(image, scaledIcon);
	double width = image.getWidth() * ratio;
	double height = image.getHeight() * ratio;
	g.drawImage(image, (int) ((scaledIcon.getWidth() - width) / 2), (int) ((scaledIcon.getHeight() - height) / 2),
			(int) (width), (int) (height), null);
	g.dispose();

	return convertToByteBuffer(scaledIcon);
}
 
Example 11
Project: jdk8u-jdk   File: JLightweightFrame.java   View Source Code Vote up 5 votes
private void resizeBuffer(int width, int height, int newScaleFactor) {
        bbImage = new BufferedImage(width*newScaleFactor,height*newScaleFactor,
                                    BufferedImage.TYPE_INT_ARGB_PRE);
    int[] pixels= ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
    if (copyBufferEnabled) {
        syncCopyBuffer(true, 0, 0, width, height, newScaleFactor);
        pixels = copyBuffer;
    }
    content.imageBufferReset(pixels, 0, 0, width, height,
                             width * newScaleFactor, newScaleFactor);
}
 
Example 12
Project: openjdk-jdk10   File: CPrinterJob.java   View Source Code Vote up 5 votes
private PeekGraphics createFirstPassGraphics(PrinterJob printerJob, PageFormat page) {
    // This is called from the native side.
    BufferedImage bimg = new BufferedImage((int)Math.round(page.getWidth()), (int)Math.round(page.getHeight()), BufferedImage.TYPE_INT_ARGB_PRE);
    PeekGraphics peekGraphics = createPeekGraphics(bimg.createGraphics(), printerJob);
    Rectangle2D pageFormatArea = getPageFormatArea(page);
    initPrinterGraphics(peekGraphics, pageFormatArea);
    return peekGraphics;
}
 
Example 13
Project: openjdk-jdk10   File: AquaIcon.java   View Source Code Vote up 5 votes
public static Image getImageForIcon(final Icon i) {
    if (i instanceof ImageIcon) return ((ImageIcon)i).getImage();

    final int w = i.getIconWidth();
    final int h = i.getIconHeight();

    if (w <= 0 || h <= 0) return null;

    // This could be any kind of icon, so we need to make a buffer for it, draw it and then pass the new image off to appkit.
    final BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
    final Graphics g = image.getGraphics();
    i.paintIcon(null, g, 0, 0);
    g.dispose();
    return image;
}
 
Example 14
Project: OpenJSharp   File: Destinations.java   View Source Code Vote up 5 votes
public static void init() {
    destroot = new Group.EnableSet(TestEnvironment.globaloptroot,
                                   "dest", "Output Destination Options");

    new Screen();
    new OffScreen();

    if (GraphicsTests.hasGraphics2D) {
        if (ImageTests.hasCompatImage) {
            compatimgdestroot =
                new Group.EnableSet(destroot, "compatimg",
                                    "Compatible Image Destinations");
            compatimgdestroot.setHorizontal();

            new CompatImg();
            new CompatImg(Transparency.OPAQUE);
            new CompatImg(Transparency.BITMASK);
            new CompatImg(Transparency.TRANSLUCENT);
        }

        if (ImageTests.hasVolatileImage) {
            new VolatileImg();
        }

        bufimgdestroot = new Group.EnableSet(destroot, "bufimg",
                                             "BufferedImage Destinations");

        new BufImg(BufferedImage.TYPE_INT_RGB);
        new BufImg(BufferedImage.TYPE_INT_ARGB);
        new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
        new BufImg(BufferedImage.TYPE_3BYTE_BGR);
        new BufImg(BufferedImage.TYPE_BYTE_INDEXED);
        new BufImg(BufferedImage.TYPE_BYTE_GRAY);
        new CustomImg();
    }
}
 
Example 15
Project: OpenJSharp   File: OGLBlitLoops.java   View Source Code Vote up 5 votes
private synchronized void complexClipBlit(SurfaceData src, SurfaceData dst,
                                          Composite comp, Region clip,
                                          int sx, int sy, int dx, int dy,
                                          int w, int h) {
    SurfaceData cachedSrc = null;
    if (srcTmp != null) {
        // use cached intermediate surface, if available
        cachedSrc = srcTmp.get();
    }

    // We can convert argb_pre data from OpenGL surface in two places:
    // - During OpenGL surface -> SW blit
    // - During SW -> SW blit
    // The first one is faster when we use opaque OGL surface, because in
    // this case we simply skip conversion and use color components as is.
    // Because of this we align intermediate buffer type with type of
    // destination not source.
    final int type = typeval == OGLSurfaceData.PF_INT_ARGB_PRE ?
                     BufferedImage.TYPE_INT_ARGB_PRE :
                     BufferedImage.TYPE_INT_ARGB;

    src = convertFrom(this, src, sx, sy, w, h, cachedSrc, type);

    // copy intermediate SW to destination SW using complex clip
    final Blit performop = Blit.getFromCache(src.getSurfaceType(),
                                             CompositeType.SrcNoEa,
                                             dst.getSurfaceType());
    performop.Blit(src, dst, comp, clip, 0, 0, dx, dy, w, h);

    if (src != cachedSrc) {
        // cache the intermediate surface
        srcTmp = new WeakReference<>(src);
    }
}
 
Example 16
Project: jdk8u-jdk   File: AquaInternalFrameDockIconUI.java   View Source Code Vote up 5 votes
void updateIcon() {
    final Object priorIcon = fFrame.getClientProperty(CACHED_FRAME_ICON_KEY);
    if (priorIcon instanceof ImageIcon) {
        setIcon((ImageIcon)priorIcon);
        return;
    }

    int width = fFrame.getWidth();
    int height = fFrame.getHeight();

    // Protect us from unsized frames, like in JCK test DefaultDesktopManager2008
    if (width <= 0 || height <= 0) {
        width = 128;
        height = 128;
    }

    final Image fImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    final Graphics g = fImage.getGraphics();
    fFrame.paint(g);
    g.dispose();

    final float scale = (float)fDesktopIcon.getWidth() / (float)Math.max(width, height) * 0.89f;
    // Sending in -1 for width xor height causes it to maintain aspect ratio
    final ImageIcon icon = new ImageIcon(fImage.getScaledInstance((int)(width * scale), -1, Image.SCALE_SMOOTH));
    fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, icon);
    setIcon(icon);
}
 
Example 17
Project: OpenJSharp   File: JLightweightFrame.java   View Source Code Vote up 5 votes
private void resizeBuffer(int width, int height, int newScaleFactor) {
        bbImage = new BufferedImage(width*newScaleFactor,height*newScaleFactor,
                                    BufferedImage.TYPE_INT_ARGB_PRE);
    int[] pixels= ((DataBufferInt)bbImage.getRaster().getDataBuffer()).getData();
    if (copyBufferEnabled) {
        syncCopyBuffer(true, 0, 0, width, height, newScaleFactor);
        pixels = copyBuffer;
    }
    content.imageBufferReset(pixels, 0, 0, width, height,
                             width * newScaleFactor, newScaleFactor);
}
 
Example 18
Project: OpenJSharp   File: AquaInternalFrameDockIconUI.java   View Source Code Vote up 5 votes
void updateIcon() {
    final Object priorIcon = fFrame.getClientProperty(CACHED_FRAME_ICON_KEY);
    if (priorIcon instanceof ImageIcon) {
        setIcon((ImageIcon)priorIcon);
        return;
    }

    int width = fFrame.getWidth();
    int height = fFrame.getHeight();

    // Protect us from unsized frames, like in JCK test DefaultDesktopManager2008
    if (width <= 0 || height <= 0) {
        width = 128;
        height = 128;
    }

    final Image fImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
    final Graphics g = fImage.getGraphics();
    fFrame.paint(g);
    g.dispose();

    final float scale = (float)fDesktopIcon.getWidth() / (float)Math.max(width, height) * 0.89f;
    // Sending in -1 for width xor height causes it to maintain aspect ratio
    final ImageIcon icon = new ImageIcon(fImage.getScaledInstance((int)(width * scale), -1, Image.SCALE_SMOOTH));
    fFrame.putClientProperty(CACHED_FRAME_ICON_KEY, icon);
    setIcon(icon);
}
 
Example 19
Project: jdk8u-jdk   File: AquaButtonLabeledUI.java   View Source Code Vote up 4 votes
protected Icon getInstance() {
    return new ImageIcon(new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_ARGB_PRE));
}
 
Example 20
Project: OpenJSharp   File: PathGraphics.java   View Source Code Vote up 4 votes
/**
 * Return true if the BufferedImage argument has non-opaque
 * bits in it and therefore can not be directly rendered by
 * GDI. Return false if the image is opaque. If this function
 * can not tell for sure whether the image has transparent
 * pixels then it assumes that it does.
 */
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
    ColorModel colorModel = bufferedImage.getColorModel();
    boolean hasTransparency = colorModel == null
        ? true
        : colorModel.getTransparency() != ColorModel.OPAQUE;

    /*
     * For the default INT ARGB check the image to see if any pixels are
     * really transparent. If there are no transparent pixels then the
     * transparency of the color model can be ignored.
     * We assume that IndexColorModel images have already been
     * checked for transparency and will be OPAQUE unless they actually
     * have transparent pixels present.
     */
    if (hasTransparency && bufferedImage != null) {
        if (bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB ||
            bufferedImage.getType()==BufferedImage.TYPE_INT_ARGB_PRE) {
            DataBuffer db =  bufferedImage.getRaster().getDataBuffer();
            SampleModel sm = bufferedImage.getRaster().getSampleModel();
            if (db instanceof DataBufferInt &&
                sm instanceof SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel psm =
                    (SinglePixelPackedSampleModel)sm;
                // Stealing the data array for reading only...
                int[] int_data =
                    SunWritableRaster.stealData((DataBufferInt) db, 0);
                int x = bufferedImage.getMinX();
                int y = bufferedImage.getMinY();
                int w = bufferedImage.getWidth();
                int h = bufferedImage.getHeight();
                int stride = psm.getScanlineStride();
                boolean hastranspixel = false;
                for (int j = y; j < y+h; j++) {
                    int yoff = j * stride;
                    for (int i = x; i < x+w; i++) {
                        if ((int_data[yoff+i] & 0xff000000)!=0xff000000 ) {
                            hastranspixel = true;
                            break;
                        }
                    }
                    if (hastranspixel) {
                        break;
                    }
                }
                if (hastranspixel == false) {
                    hasTransparency = false;
                }
            }
        }
    }

    return hasTransparency;
}