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

The following are Jave code examples for showing how to use TYPE_INT_ARGB 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: ImageGenerator.java   View Source Code Vote up 6 votes
public ImageGenerator(int _width, int _height, Color bgColor)
{
      width = _width;
      height = _height;
      bi = new BufferedImage(
          width,
          height,
          BufferedImage.TYPE_INT_ARGB);
      Graphics gr = bi.getGraphics();
      if(null==bgColor){
          bgColor = Color.WHITE;
      }
      gr.setColor(bgColor);
      gr.fillRect(0, 0, width, height);
      paint(gr);
      gr.dispose();
}
 
Example 2
Project: jdk8u-jdk   File: RenderTests.java   View Source Code Vote up 6 votes
private TexturePaint makeTexturePaint(int size, boolean alpha) {
    int s2 = size / 2;
    int type =
        alpha ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
    BufferedImage img = new BufferedImage(size, size, type);
    Color[] colors = makeGradientColors(4, alpha);
    Graphics2D g2d = img.createGraphics();
    g2d.setComposite(AlphaComposite.Src);
    g2d.setColor(colors[0]);
    g2d.fillRect(0, 0, s2, s2);
    g2d.setColor(colors[1]);
    g2d.fillRect(s2, 0, s2, s2);
    g2d.setColor(colors[3]);
    g2d.fillRect(0, s2, s2, s2);
    g2d.setColor(colors[2]);
    g2d.fillRect(s2, s2, s2, s2);
    g2d.dispose();
    Rectangle2D bounds = new Rectangle2D.Float(0, 0, size, size);
    return new TexturePaint(img, bounds);
}
 
Example 3
Project: sbc-qsystem   File: FInfoDialog.java   View Source Code Vote up 6 votes
private Image resizeToBig(Image originalImage, int biggerWidth, int biggerHeight) {
    final BufferedImage resizedImage = new BufferedImage(biggerWidth, biggerHeight,
        BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g = resizedImage.createGraphics();

    g.setComposite(AlphaComposite.Src);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
        RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g.drawImage(originalImage, 0, 0, biggerWidth, biggerHeight, this);
    g.dispose();

    return resizedImage;
}
 
Example 4
Project: openjdk-jdk10   File: TableScrollPaneCorner.java   View Source Code Vote up 6 votes
/**
 * Paint the component using the Nimbus Table Header Background Painter
 */
@Override protected void paintComponent(Graphics g) {
    @SuppressWarnings("unchecked")
    Painter<JComponent> painter = (Painter) UIManager.get(
        "TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter");
    if (painter != null){
        if (g instanceof Graphics2D){
            painter.paint((Graphics2D)g,this,getWidth()+1,getHeight());
        } else {
            // paint using image to not Graphics2D to support
            // Java 1.1 printing API
            BufferedImage img =  new BufferedImage(getWidth(),getHeight(),
                    BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = (Graphics2D)img.getGraphics();
            painter.paint(g2,this,getWidth()+1,getHeight());
            g2.dispose();
            g.drawImage(img,0,0,null);
            img = null;
        }
    }
}
 
Example 5
Project: OpenJSharp   File: TableScrollPaneCorner.java   View Source Code Vote up 6 votes
/**
 * Paint the component using the Nimbus Table Header Background Painter
 */
@Override protected void paintComponent(Graphics g) {
    Painter painter = (Painter) UIManager.get(
        "TableHeader:\"TableHeader.renderer\"[Enabled].backgroundPainter");
    if (painter != null){
        if (g instanceof Graphics2D){
            painter.paint((Graphics2D)g,this,getWidth()+1,getHeight());
        } else {
            // paint using image to not Graphics2D to support
            // Java 1.1 printing API
            BufferedImage img =  new BufferedImage(getWidth(),getHeight(),
                    BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = (Graphics2D)img.getGraphics();
            painter.paint(g2,this,getWidth()+1,getHeight());
            g2.dispose();
            g.drawImage(img,0,0,null);
            img = null;
        }
    }
}
 
Example 6
Project: BHBot   File: MarvinImage.java   View Source Code Vote up 6 votes
/**
 * Resize and return the image passing the new height and width
 * @param height
 * @param width
 * @return
 */
public BufferedImage getBufferedImage(int width, int height)
{
	// using the new approach of Java 2D API 
	BufferedImage buf = new BufferedImage(width,height, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g2d = (Graphics2D) buf.getGraphics();
	g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2d.drawImage(image,0,0,width,height,null);
	g2d.dispose();
	return(buf);
}
 
Example 7
Project: gate-core   File: LeftArrowIcon.java   View Source Code Vote up 5 votes
public Image getImage() {
	BufferedImage image =
           new BufferedImage(getIconWidth(), getIconHeight(),
                   BufferedImage.TYPE_INT_ARGB);
   	Graphics2D g = image.createGraphics();
   	paintIcon(null, g, 0, 0);
   	g.dispose();
   	return image;
}
 
Example 8
Project: jmonet   File: CanvasTransferHandler.java   View Source Code Vote up 5 votes
private BufferedImage toBufferedImage(Image source) {
    if (source instanceof BufferedImage) {
        return (BufferedImage) source;
    }

    // Create a buffered image with transparency
    BufferedImage dest = new BufferedImage(source.getWidth(null), source.getHeight(null), BufferedImage.TYPE_INT_ARGB);

    // Draw the image on to the buffered image
    Graphics2D g = dest.createGraphics();
    g.drawImage(source, 0, 0, null);
    g.dispose();

    return dest;
}
 
Example 9
Project: OpenJSharp   File: Win32ShellFolder2.java   View Source Code Vote up 5 votes
private static Image makeIcon(long hIcon, boolean getLargeIcon) {
    if (hIcon != 0L && hIcon != -1L) {
        // Get the bits.  This has the side effect of setting the imageHash value for this object.
        int size = getLargeIcon ? 32 : 16;
        int[] iconBits = getIconBits(hIcon, size);
        if (iconBits != null) {
            BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
            img.setRGB(0, 0, size, size, iconBits, 0, size);
            return img;
        }
    }
    return null;
}
 
Example 10
Project: incubator-netbeans   File: ProfilerTreeTable.java   View Source Code Vote up 5 votes
protected void drawCentered(Component c, Graphics graphics, Icon icon,
                        int x, int y) {
    int w = icon.getIconWidth();
    int h = icon.getIconHeight();
    image[0] = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    super.drawCentered(c, image[0].getGraphics(), icon, w / 2, h / 2);
}
 
Example 11
Project: PokeData   File: MapTileData.java   View Source Code Vote up 5 votes
private BufferedImage prepareTileset(ROM rom, ROMData data, BlockRenderer renderer, MapData mapData, boolean complete) {
    Tileset global = TilesetCache.get(rom, data, mapData.getGlobalTilesetPtr());
    Tileset local = TilesetCache.get(rom, data, mapData.getLocalTilesetPtr());

    renderer.setTilesets(global, local);

    Dimension dimension = getDimension(data);

    if (complete && rom.getGame().isGem()) {
        dimension.height = 3048;
    }

    return new BufferedImage(dimension.width, dimension.height, BufferedImage.TYPE_INT_ARGB);
}
 
Example 12
Project: DicomViewer   File: DataLoader.java   View Source Code Vote up 5 votes
public static BufferedImage toBufferedImage(final ImageIcon icon) {
    if (icon == null) return null;
    final int w = icon.getIconWidth(), h = icon.getIconHeight();
    final BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); 
    final Graphics g = bi.createGraphics();
    icon.paintIcon(null, g, 0,0);
    g.dispose();
    return bi;
}
 
Example 13
Project: Photato   File: ImageHelper.java   View Source Code Vote up 5 votes
public static BufferedImage resizeImageSmooth(BufferedImage image, int wantedWidth, int wantedHeight) {
    Image scaledImage = image.getScaledInstance(wantedWidth, wantedHeight, Image.SCALE_SMOOTH);
    BufferedImage imageBuff = new BufferedImage(wantedWidth, wantedHeight, BufferedImage.TYPE_INT_ARGB);
    Graphics g = imageBuff.createGraphics();
    g.drawImage(scaledImage, 0, 0, null, null);
    g.dispose();

    return imageBuff;
}
 
Example 14
Project: JavaPPTX   File: PPWindowImage.java   View Source Code Vote up 5 votes
private Image createWindowImage() {
   int iw = (int) (sw + 0.99);
   int ih = (int) (sh + 0.99);
   BufferedImage image = new BufferedImage(iw, ih,
                                           BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = image.createGraphics();
   g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                      RenderingHints.VALUE_ANTIALIAS_ON);
   g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                      RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
   fillBackground(g);
   drawTitleBar(g);
   drawWindowBody(g);
   return image;
}
 
Example 15
Project: DicomViewer   File: DataLoader.java   View Source Code Vote up 5 votes
public static BufferedImage getImgARGB(final String name) {
    try {
        BufferedImage img = ImageIO.read(new File(name));
        if (img != null) {
            BufferedImage img2 = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2 = (Graphics2D) img2.getGraphics();
            g2.drawImage(img, null, 0, 0);
            g2.dispose();
            return img2;
        }
    } catch (IOException ex) {
        Logger.getLogger(DataLoader.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}
 
Example 16
Project: gate-core   File: ApplicationIcon.java   View Source Code Vote up 5 votes
public Image getImage() {
	BufferedImage image =
           new BufferedImage(getIconWidth(), getIconHeight(),
                   BufferedImage.TYPE_INT_ARGB);
   	Graphics2D g = image.createGraphics();
   	paintIcon(null, g, 0, 0);
   	g.dispose();
   	return image;
}
 
Example 17
Project: VTerminal   File: DrawTest.java   View Source Code Vote up 5 votes
@Test
public void testWithValidInputs_withVerticalFlip() {
    final int width = font.getWidth();
    final int height = font.getHeight();
    final BufferedImage temp = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);

    character.setFlippedVertically(true);
    character.draw((Graphics2D) temp.getGraphics(), new ImageCache(font), 0, 0);
}
 
Example 18
Project: lams   File: Scalr.java   View Source Code Vote up 4 votes
/**
    * Used to copy a {@link BufferedImage} from a non-optimal type into a new
    * {@link BufferedImage} instance of an optimal type (RGB or ARGB). If
    * <code>src</code> is already of an optimal type, then it is returned
    * unmodified.
    * <p/>
    * This method is meant to be used by any calling code (imgscalr's or
    * otherwise) to convert any inbound image from a poorly supported image
    * type into the 2 most well-supported image types in Java2D (
    * {@link BufferedImage#TYPE_INT_RGB} or {@link BufferedImage#TYPE_INT_ARGB}
    * ) in order to ensure all subsequent graphics operations are performed as
    * efficiently and correctly as possible.
    * <p/>
    * When using Java2D to work with image types that are not well supported,
    * the results can be anything from exceptions bubbling up from the depths
    * of Java2D to images being completely corrupted and just returned as solid
    * black.
    * 
    * @param src
    *            The image to copy (if necessary) into an optimally typed
    *            {@link BufferedImage}.
    * 
    * @return a representation of the <code>src</code> image in an optimally
    *         typed {@link BufferedImage}, otherwise <code>src</code> if it was
    *         already of an optimal type.
    * 
    * @throws IllegalArgumentException
    *             if <code>src</code> is <code>null</code>.
    */
   protected static BufferedImage copyToOptimalImage(BufferedImage src) throws IllegalArgumentException {
if (src == null)
    throw new IllegalArgumentException("src cannot be null");

// Calculate the type depending on the presence of alpha.
int type = (src.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB
	: BufferedImage.TYPE_INT_ARGB);
BufferedImage result = new BufferedImage(src.getWidth(), src.getHeight(), type);

// Render the src image into our new optimal source.
Graphics g = result.getGraphics();
g.drawImage(src, 0, 0, null);
g.dispose();

return result;
   }
 
Example 19
Project: jdk8u-jdk   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;
}
 
Example 20
Project: jmt   File: ImageLoader.java   View Source Code Vote up 3 votes
/**
 * Merge two icons together. Output icon dimension is the same as background one.
 * @param background background icon
 * @param overlay overlay icon, needs to be transparent (will be moved and cropped)
 * @param cropMin minimum crop point for overlay icon (0,0 for no crop)
 * @param cropMax maximum crop point for overlay icon (width and height for no crop)
 * @param move upper left corner where cropped overlay image should be positioned on background image
 * @return merged icon
 */
protected ImageIcon mergeIcons(ImageIcon background, ImageIcon overlay, Point cropMin, Point cropMax, Point move) {
	BufferedImage out = new BufferedImage(background.getIconWidth(), background.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = out.createGraphics();
	g.drawImage(background.getImage(), 0, 0, null);
	g.drawImage(overlay.getImage(), move.x, move.y, move.x + cropMax.x - cropMin.x, move.y + cropMax.y - cropMin.y, cropMin.x, cropMin.y,
			cropMax.x, cropMax.y, null);
	return new ImageIcon(out);
}