List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
From source file:CompositingDST.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red);// w w w . j a v a 2 s. co m gbi.fillRect(0, 0, 40, 40); gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:bayesGame.ui.painter.OrNodePainter.java
public static Image paintPercentage(Color gridColor, Color falseColor, int size, int squaresize, BayesNode node, Fraction parentNode1Probability, Fraction parentNode2Probability) { BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); NodePainter.graphicBackgroundPainter(g, 0, 0, size, size); // get non-zero truth table entries from the node List<Map<Object, Boolean>> nonZeroEntries = node.getNonZeroProbabilities(); // get the identities of its parents by taking the first map and querying it // for KeySet, subtracting the object representing the node itself Set<Object> nodeParents = nonZeroEntries.get(0).keySet(); nodeParents.remove(node.type);// w w w. j a v a2 s . c om if (nodeParents.size() > 2) { throw new IllegalArgumentException("OR node with more than 2 parents not yet implemented"); } Object[] nodeParentsArray = nodeParents.toArray(); Object parent1 = nodeParentsArray[0]; Object parent2 = nodeParentsArray[1]; // for each map, check the truth table entry it corresponds to and color // those appropriately boolean p1true_p2true = false; boolean p1true_p2false = false; boolean p1false_p2true = false; boolean p1false_p2false = false; for (Map<Object, Boolean> map : nonZeroEntries) { Boolean parent1truth = map.get(parent1); Boolean parent2truth = map.get(parent2); if (parent1truth && parent2truth) { p1true_p2true = true; } else if (parent1truth && !parent2truth) { p1true_p2false = true; } else if (!parent1truth && parent2truth) { p1false_p2true = true; } else if (!parent1truth && !parent2truth) { p1false_p2false = true; } } int XSize = parentNode1Probability.multiply(size).intValue(); int X_Size = size - XSize; int YSize = parentNode2Probability.multiply(size).intValue(); int Y_Size = size - YSize; if (p1true_p2true) { NodePainter.squarePainter(g, 0, 0, XSize, YSize, gridColor, Color.BLACK); } else { NodePainter.squarePainter(g, 0, 0, XSize, YSize, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR, Color.BLACK); } NodePainter.squarePainter(g, XSize, 0, X_Size, YSize, gridColor, Color.BLACK); NodePainter.squarePainter(g, 0, YSize, XSize, Y_Size, gridColor, Color.BLACK); if (p1false_p2false) { NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, falseColor, Color.BLACK); } else { NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR, Color.BLACK); } return img; }
From source file:CompositingDST_ATOP.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red);//from w ww . j ava 2 s .c o m gbi.fillRect(0, 0, 40, 40); gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:CompositingDST_ATOP.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OUT, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red);/* w w w . ja v a 2 s.c om*/ gbi.fillRect(0, 0, 40, 40); gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:CompositingDST_ATOP.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_OUT, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red);//from w w w .j a va 2 s . c o m gbi.fillRect(0, 0, 40, 40); gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:bayesGame.ui.painter.AndNodePainter.java
public static Image paintPercentage(Color gridColor, Color falseColor, int size, int squaresize, BayesNode node, Fraction parentNode1Probability, Fraction parentNode2Probability) { BufferedImage img = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); NodePainter.graphicBackgroundPainter(g, 0, 0, size, size); // get non-zero truth table entries from the node List<Map<Object, Boolean>> nonZeroEntries = node.getNonZeroProbabilities(); // get the identities of its parents by taking the first map and querying it // for KeySet, subtracting the object representing the node itself Set<Object> nodeParents = nonZeroEntries.get(0).keySet(); nodeParents.remove(node.type);/*from ww w . j a v a 2 s . co m*/ if (nodeParents.size() > 2) { throw new IllegalArgumentException("AND node with more than 2 parents not yet implemented"); } Object[] nodeParentsArray = nodeParents.toArray(); Object parent1 = nodeParentsArray[0]; Object parent2 = nodeParentsArray[1]; // for each map, check the truth table entry it corresponds to and color // those appropriately boolean p1true_p2true = false; boolean p1true_p2false = false; boolean p1false_p2true = false; boolean p1false_p2false = false; for (Map<Object, Boolean> map : nonZeroEntries) { Boolean parent1truth = map.get(parent1); Boolean parent2truth = map.get(parent2); if (parent1truth && parent2truth) { p1true_p2true = true; } else if (parent1truth && !parent2truth) { p1true_p2false = true; } else if (!parent1truth && parent2truth) { p1false_p2true = true; } else if (!parent1truth && !parent2truth) { p1false_p2false = true; } } Color whiteColor = Color.WHITE; int XSize = parentNode1Probability.multiply(size).intValue(); int X_Size = size - XSize; int YSize = parentNode2Probability.multiply(size).intValue(); int Y_Size = size - YSize; if (p1true_p2true) { NodePainter.squarePainter(g, 0, 0, XSize, YSize, gridColor, Color.BLACK); } else { NodePainter.squarePainter(g, 0, 0, XSize, YSize, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR, Color.BLACK); } NodePainter.squarePainter(g, XSize, 0, X_Size, YSize, falseColor, Color.BLACK); NodePainter.squarePainter(g, 0, YSize, XSize, Y_Size, falseColor, Color.BLACK); if (p1false_p2false) { NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, falseColor, Color.BLACK); } else { NodePainter.squarePainter(g, XSize, YSize, X_Size, Y_Size, NodePainter.RECTANGLE_BOX_BACKGROUND_COLOR, Color.BLACK); } return img; }
From source file:CompositingDST_ATOP.java
public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_ATOP, 0.5f); BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); gbi.setPaint(Color.red);//from w ww. j a v a 2 s . c o m gbi.fillRect(0, 0, 40, 40); gbi.setComposite(ac); gbi.setPaint(Color.green); gbi.fillRect(5, 5, 40, 40); g2d.drawImage(buffImg, 20, 20, null); }
From source file:ImageFlip.java
public void paint(Graphics g) { Image myImage = new ImageIcon("yourImage.jpg").getImage(); BufferedImage bufferedImage = new BufferedImage(myImage.getWidth(null), myImage.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) g; Graphics gb = bufferedImage.getGraphics(); gb.drawImage(myImage, 0, 0, null);/* w w w. j av a2s . c om*/ gb.dispose(); AffineTransform tx = AffineTransform.getScaleInstance(-1, 1); tx.translate(-myImage.getWidth(null), 0); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); bufferedImage = op.filter(bufferedImage, null); g2d.drawImage(myImage, 10, 10, null); g2d.drawImage(bufferedImage, null, 300, 10); }
From source file:Main.java
/** * Quickly crops an image from its source. * @param src The source image.//from w w w . j a v a 2 s . c o m * @param x The x coordinate to start at. * @param y The y coordinate to start at. * @param width The width to clip. * @param height The height to clip. * @return */ public static BufferedImage imgUtilFastCrop(BufferedImage src, int x, int y, int width, int height) { if (src == null) return null; if (x == 0 && y == 0 && width == src.getWidth() && height == src.getHeight()) return imgUtilFastCopy(src); else { BufferedImage b = new BufferedImage(width, height, src.getType()); Graphics g = b.getGraphics(); g.drawImage(src, -x, -y, null); g.dispose(); return b; } }
From source file:com.pureinfo.srm.common.ImageHelper.java
public static void drawImage(String _sString, OutputStream _os) throws PureException { int nWidth = 200; int nHeight = 50; String sText = _sString;//from ww w . j av a 2 s . c om BufferedImage image = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); for (int i = 0; i < sText.length(); i++) { draw(String.valueOf(sText.charAt(i)), g2, i * nWidth / sText.length(), 0, (i + 1) * nWidth / sText.length(), nHeight); } g2.dispose(); try { EncoderUtil.writeBufferedImage(image, ImageFormat.PNG, _os); } catch (Exception ex) { throw new PureException(PureException.UNKNOWN, "", ex); } }