java.awt.image.BufferedImage#coerceData()源码实例Demo

下面列出了java.awt.image.BufferedImage#coerceData() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MyBox   文件: ImageManufacture.java
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;
    }
}
 
源代码2 项目: Visage   文件: Textures.java
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();
}
 
源代码3 项目: java-swing-tips   文件: MainPanel.java
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;
}
 
源代码4 项目: MyBox   文件: ImageManufacture.java
public static BufferedImage createCompatibleImage(int width, int height,
        int transparency) {
    BufferedImage image = getGraphicsConfiguration().createCompatibleImage(width, height, transparency);
    image.coerceData(true);
    return image;
}