Java Code Examples for java.awt.image.BufferedImage#coerceData()

The following examples show how to use java.awt.image.BufferedImage#coerceData() . 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: ImageManufacture.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static BufferedImage premultipliedAlpha2(BufferedImage source,
        boolean removeAlpha) {
    try {
        if (source == null || !hasAlpha(source)
                || (source.isAlphaPremultiplied() && !removeAlpha)) {
            return source;
        }
        BufferedImage target = clone(source);
        target.coerceData(true);
        if (removeAlpha) {
            target = removeAlpha(target);
        }
        return target;
    } catch (Exception e) {
        logger.error(e.toString());
        return source;
    }
}
 
Example 2
Source File: Textures.java    From Visage with MIT License 6 votes vote down vote up
public static void upload(BufferedImage img, int format, int tex) {
	int width = img.getWidth();
	int height = img.getHeight();
	if (Visage.trace) Visage.log.finest("Uploading "+width+"x"+height+" ("+(width*height)+" pixel) image");
	
	BufferedImage unindexed = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
	
	int[] argb = new int[width*height];
	img.getRGB(0, 0, width, height, argb, 0, width);
	
	unindexed.setRGB(0, 0, width, height, argb, 0, width);
	unindexed.coerceData(true);
	unindexed.getRGB(0, 0, width, height, argb, 0, width);
	
	IntBuffer buf = BufferUtils.createIntBuffer(width*height);
	buf.put(argb);
	buf.flip();
	
	glBindTexture(GL_TEXTURE_2D, tex);
	glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, buf);
	
	checkGLError();
}
 
Example 3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static <E> BufferedImage createCompactDragImage(JList<E> source, int w, int h) {
  if (w <= 0 || h <= 0) {
    throw new IllegalArgumentException("width and height must be > 0");
  }
  int[] selectedIndices = source.getSelectedIndices();
  BufferedImage br = source.getGraphicsConfiguration().createCompatibleImage(w, h, Transparency.TRANSLUCENT);
  Graphics2D g2 = br.createGraphics();
  ListCellRenderer<? super E> renderer = source.getCellRenderer();
  int idx = selectedIndices[0];
  E valueAt = source.getModel().getElementAt(idx);
  Component c = renderer.getListCellRendererComponent(source, valueAt, idx, false, false);
  Rectangle rect = source.getCellBounds(idx, idx);
  SwingUtilities.paintComponent(g2, c, source, 0, 0, rect.width, rect.height);
  int selectedCount = selectedIndices.length;
  boolean isMoreThanOneItemSelected = selectedCount > 1;
  if (isMoreThanOneItemSelected) {
    LABEL.setText(Objects.toString(selectedCount));
    Dimension d = LABEL.getPreferredSize();
    SwingUtilities.paintComponent(g2, LABEL, source, (w - d.width) / 2, (h - d.height) / 2, d.width, d.height);
  }
  g2.dispose();
  br.coerceData(true);
  return br;
}
 
Example 4
Source File: ImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static BufferedImage createCompatibleImage(int width, int height,
        int transparency) {
    BufferedImage image = getGraphicsConfiguration().createCompatibleImage(width, height, transparency);
    image.coerceData(true);
    return image;
}