List of usage examples for java.awt Graphics2D drawImage
public abstract void drawImage(BufferedImage img, BufferedImageOp op, int x, int y);
From source file:Main.java
private void renderImage() throws Exception { if (alignment == LINEAR_LEFT_TO_RIGHT) { int[] rgbRange = loadRGBRange(width, rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + y * width] = rgbRange[x]; }/*from w ww. j a v a 2 s .c o m*/ } } else if (alignment == LINEAR_RIGHT_TO_LEFT) { int[] rgbRange = loadRGBRange(width, rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + y * width] = rgbRange[width - x - 1]; } } } else if (alignment == LINEAR_BOTTOM_TO_TOP) { int[] rgbRange = loadRGBRange(height, rgbs, positions); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { pixels[x + y * width] = rgbRange[height - y - 1]; } } } else if (alignment == LINEAR_TOP_TO_BOTTOM) { int[] rgbRange = loadRGBRange(height, rgbs, positions); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { pixels[x + y * width] = rgbRange[y]; } } } else if (alignment == RADIAL_FROM_TOP_LEFT_CORNER) { int[] rgbRange = loadRGBRange((int) Math.sqrt((width - 1) * (width - 1) + (height - 1) * (height - 1)), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + y * width] = rgbRange[(int) Math.sqrt((x - 1) * (x - 1) + (y - 1) * (y - 1))]; } } } else if (alignment == RADIAL_FROM_BOTTOM_LEFT_CORNER) { int[] rgbRange = loadRGBRange((int) Math.sqrt((width - 1) * (width - 1) + (height - 1) * (height - 1)), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + (height - y - 1) * width] = rgbRange[(int) Math .sqrt((x - 1) * (x - 1) + (y - 1) * (y - 1))]; } } } else if (alignment == RADIAL_FROM_TOP_RIGHT_CORNER) { int[] rgbRange = loadRGBRange((int) Math.sqrt((width - 1) * (width - 1) + (height - 1) * (height - 1)), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[(width - x - 1) + y * width] = rgbRange[(int) Math.sqrt((x - 1) * (x - 1) + (y - 1) * (y - 1))]; } } } else if (alignment == RADIAL_FROM_BOTTOM_RIGHT_CORNER) { int[] rgbRange = loadRGBRange((int) Math.sqrt((width - 1) * (width - 1) + (height - 1) * (height - 1)), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[(width - x - 1) + (height - y - 1) * width] = rgbRange[(int) Math .sqrt((x - 1) * (x - 1) + (y - 1) * (y - 1))]; } } } else if (alignment == RADIAL_FROM_CENTER) { int[] divArray = divideArray(positions, 2); BufferedImage quad1 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_BOTTOM_RIGHT_CORNER).getImage(); BufferedImage quad2 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_BOTTOM_LEFT_CORNER).getImage(); BufferedImage quad3 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_TOP_RIGHT_CORNER).getImage(); BufferedImage quad4 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_TOP_LEFT_CORNER).getImage(); Graphics2D g = image.createGraphics(); g.drawImage(quad1, 0, 0, null); g.drawImage(quad2, width >> 1, 0, null); g.drawImage(quad3, 0, height >> 1, null); g.drawImage(quad4, width >> 1, height >> 1, null); g.dispose(); } else if (alignment == RADIAL_FROM_CORNERS) { int[] divArray = divideArray(positions, 2); BufferedImage quad1 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_TOP_LEFT_CORNER).getImage(); BufferedImage quad2 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_TOP_RIGHT_CORNER).getImage(); BufferedImage quad3 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_BOTTOM_LEFT_CORNER).getImage(); BufferedImage quad4 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.RADIAL_FROM_BOTTOM_RIGHT_CORNER).getImage(); Graphics2D g = image.createGraphics(); g.drawImage(quad1, 0, 0, null); g.drawImage(quad2, width >> 1, 0, null); g.drawImage(quad3, 0, height >> 1, null); g.drawImage(quad4, width >> 1, height >> 1, null); g.dispose(); } else if (alignment == LINEAR_DIAGONAL_UP) { int[] rgbRange = loadRGBRange((int) Math.sqrt((width - 1) * (width - 1) + (height - 1) * (height - 1)), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + (height - y - 1) * width] = rgbRange[Math.max(y - x, x - y)]; } } } else if (alignment == LINEAR_DIAGONAL_DOWN) { int[] rgbRange = loadRGBRange((int) Math.sqrt((width - 1) * (width - 1) + (height - 1) * (height - 1)), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + y * width] = rgbRange[Math.max(y - x, x - y)]; } } } else if (alignment == LINEAR_FROM_TOP_RIGHT_CORNER) { int[] rgbRange = loadRGBRange((width + height) >> 1, rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + (height - y - 1) * width] = rgbRange[rgbRange.length - ((x + y) >> 1) - 1]; } } } else if (alignment == LINEAR_FROM_TOP_LEFT_CORNER) { int[] rgbRange = loadRGBRange((width + height) >> 1, rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[(width - x - 1) + (height - y - 1) * width] = rgbRange[rgbRange.length - ((x + y) >> 1) - 1]; } } } else if (alignment == LINEAR_FROM_BOTTOM_RIGHT_CORNER) { int[] rgbRange = loadRGBRange((width + height) >> 1, rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + y * width] = rgbRange[rgbRange.length - ((x + y) >> 1) - 1]; } } } else if (alignment == LINEAR_FROM_BOTTOM_LEFT_CORNER) { int[] rgbRange = loadRGBRange((width + height) >> 1, rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[(width - x - 1) + y * width] = rgbRange[rgbRange.length - ((x + y) >> 1) - 1]; } } } else if (alignment == LINEAR_FROM_CENTER) { int[] divArray = divideArray(positions, 2); BufferedImage quad1 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_BOTTOM_RIGHT_CORNER).getImage(); BufferedImage quad2 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_BOTTOM_LEFT_CORNER).getImage(); BufferedImage quad3 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_TOP_RIGHT_CORNER).getImage(); BufferedImage quad4 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_TOP_LEFT_CORNER).getImage(); Graphics2D g = image.createGraphics(); g.drawImage(quad1, 0, 0, null); g.drawImage(quad2, width >> 1, 0, null); g.drawImage(quad3, 0, height >> 1, null); g.drawImage(quad4, width >> 1, height >> 1, null); g.dispose(); } else if (alignment == LINEAR_FROM_CORNERS) { int[] divArray = divideArray(positions, 2); BufferedImage quad1 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_TOP_LEFT_CORNER).getImage(); BufferedImage quad2 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_TOP_RIGHT_CORNER).getImage(); BufferedImage quad3 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_BOTTOM_LEFT_CORNER).getImage(); BufferedImage quad4 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.LINEAR_FROM_BOTTOM_RIGHT_CORNER).getImage(); Graphics2D g = image.createGraphics(); g.drawImage(quad1, 0, 0, null); g.drawImage(quad2, width >> 1, 0, null); g.drawImage(quad3, 0, height >> 1, null); g.drawImage(quad4, width >> 1, height >> 1, null); g.dispose(); } else if (alignment == PATH_FROM_TOP_LEFT_CORNER) { int[] rgbRange = loadRGBRange(Math.max(width, height), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + y * width] = rgbRange[Math.max(x, y)]; } } } else if (alignment == PATH_FROM_TOP_RIGHT_CORNER) { int[] rgbRange = loadRGBRange(Math.max(width, height), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[(width - x - 1) + y * width] = rgbRange[Math.max(x, y)]; } } } else if (alignment == PATH_FROM_BOTTOM_LEFT_CORNER) { int[] rgbRange = loadRGBRange(Math.max(width, height), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[x + (height - y - 1) * width] = rgbRange[Math.max(x, y)]; } } } else if (alignment == PATH_FROM_BOTTOM_RIGHT_CORNER) { int[] rgbRange = loadRGBRange(Math.max(width, height), rgbs, positions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { pixels[(width - x - 1) + (height - y - 1) * width] = rgbRange[Math.max(x, y)]; } } } else if (alignment == PATH_FROM_CENTER) { int[] divArray = divideArray(positions, 2); BufferedImage quad1 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_BOTTOM_RIGHT_CORNER).getImage(); BufferedImage quad2 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_BOTTOM_LEFT_CORNER).getImage(); BufferedImage quad3 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_TOP_RIGHT_CORNER).getImage(); BufferedImage quad4 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_TOP_LEFT_CORNER).getImage(); Graphics2D g = image.createGraphics(); g.drawImage(quad1, 0, 0, null); g.drawImage(quad2, width >> 1, 0, null); g.drawImage(quad3, 0, height >> 1, null); g.drawImage(quad4, width >> 1, height >> 1, null); g.dispose(); } else if (alignment == PATH_FROM_CORNERS) { int[] divArray = divideArray(positions, 2); BufferedImage quad1 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_TOP_LEFT_CORNER).getImage(); BufferedImage quad2 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_TOP_RIGHT_CORNER).getImage(); BufferedImage quad3 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_BOTTOM_LEFT_CORNER).getImage(); BufferedImage quad4 = new GradientImage(width >> 1, height >> 1, colors, divArray, GradientImage.PATH_FROM_BOTTOM_RIGHT_CORNER).getImage(); Graphics2D g = image.createGraphics(); g.drawImage(quad1, 0, 0, null); g.drawImage(quad2, width >> 1, 0, null); g.drawImage(quad3, 0, height >> 1, null); g.drawImage(quad4, width >> 1, height >> 1, null); g.dispose(); } }
From source file:BufferedDraw.java
public void update(Graphics g) { Graphics2D g2 = (Graphics2D) g; if (firstTime) { Dimension dim = getSize(); int w = dim.width; int h = dim.height; area = new Rectangle(dim); bi = (BufferedImage) createImage(w, h); big = bi.createGraphics();/* www . ja va 2s. c o m*/ rect.setLocation(w / 2 - 50, h / 2 - 25); big.setStroke(new BasicStroke(8.0f)); firstTime = false; } big.setColor(Color.white); big.clearRect(0, 0, area.width, area.height); big.setPaint(Color.red); big.draw(rect); big.setPaint(Color.blue); big.fill(rect); g2.drawImage(bi, 0, 0, this); }
From source file:org.dishevelled.piccolo.sprite.statemachine.AbstractStateMachineSprite.java
@Override public final void paint(final PPaintContext paintContext) { if (currentAnimation != null) { Graphics2D g = paintContext.getGraphics(); Image currentFrame = currentAnimation.getCurrentFrame(); PBounds bounds = getBoundsReference(); double w = currentFrame.getWidth(null); double h = currentFrame.getHeight(null); g.translate(bounds.getX(), bounds.getY()); g.scale(bounds.getWidth() / w, bounds.getHeight() / h); g.drawImage(currentFrame, 0, 0, null); g.scale(w / bounds.getWidth(), h / bounds.getHeight()); g.translate(-1 * bounds.getX(), -1 * bounds.getY()); }//from ww w .j a v a2 s.co m }
From source file:ShowOff.java
protected void drawImageMosaic(Graphics2D g2) { int side = 36; int width = mImage.getWidth(); int height = mImage.getHeight(); for (int y = 0; y < height; y += side) { for (int x = 0; x < width; x += side) { float xBias = (float) x / (float) width; float yBias = (float) y / (float) height; float alpha = 1.0f - Math.abs(xBias - yBias); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); int w = Math.min(side, width - x); int h = Math.min(side, height - y); BufferedImage tile = mImage.getSubimage(x, y, w, h); g2.drawImage(tile, x, y, null); }//from ww w . j av a 2 s . c o m } g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); }
From source file:de.ailis.wlandsuite.ExtractMaps.java
/** * @see de.ailis.wlandsuite.cli.ExtractProg#extract(java.io.File, * java.io.File)/*from w ww . j av a 2 s . co m*/ */ @Override public void extract(File input, File output) throws IOException { Game game1, game2; Htds htds1, htds2; Sprites sprites; InputStream stream; // Read game 1 log.info("Reading game1"); stream = new FileInputStream(new File(input.getAbsolutePath() + File.separatorChar + "game1")); try { game1 = Game.read(stream); } finally { stream.close(); } // Read game 2 log.info("Reading game2"); stream = new FileInputStream(new File(input.getAbsolutePath() + File.separatorChar + "game2")); try { game2 = Game.read(stream); } finally { stream.close(); } // Read tileset 1 log.info("Reading allhtds1"); stream = new FileInputStream(new File(input.getAbsolutePath() + File.separatorChar + "allhtds1")); try { htds1 = Htds.read(stream); } finally { stream.close(); } // Read tileset 2 log.info("Reading allhtds2"); stream = new FileInputStream(new File(input.getAbsolutePath() + File.separatorChar + "allhtds2")); try { htds2 = Htds.read(stream); } finally { stream.close(); } // Read sprites stream = new FileInputStream(new File(input.getAbsolutePath() + File.separatorChar + "ic0_9.wlf")); try { log.info("Reading sprites"); sprites = Sprites.read(stream); } finally { stream.close(); } // Iterate over both game files int fileNo = 100; for (Game game : new Game[] { game1, game2 }) { // Iterate over all maps of the current game file for (GameMap gameMap : game.getMaps()) { log.info("Writing map " + fileNo); int tilesetId = gameMap.getInfo().getTileset(); int size = gameMap.getMapSize(); EgaImage image = new EgaImage(size * 16, size * 16); Graphics2D graphics = image.createGraphics(); List<Pic> tiles; if (tilesetId < 4) { tiles = htds1.getTilesets().get(tilesetId).getTiles(); } else { tiles = htds2.getTilesets().get(tilesetId - 4).getTiles(); } TileMap map = gameMap.getTileMap(); for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { int tile = map.getTile(x, y); if (tile >= 10) { graphics.drawImage(tiles.get(tile - 10), x * 16, y * 16, null); } else { graphics.drawImage(sprites.getSprites().get(tile), x * 16, y * 16, null); } } } // Write the image to disk File file = new File( String.format("%s%c%03d.png", new Object[] { output, File.separatorChar, fileNo })); ImageIO.write(image, "PNG", file); fileNo++; } fileNo = 200; } }
From source file:distribuidos.MyThread.java
private void difuminarTrozo(int x, int y, int w, int h) { preSC();/*from w w w. j a v a 2 s. c om*/ BufferedImage original = null; BufferedImage nueva = null; try { original = ImageIO.read(new File(imagepath)); nueva = ImageIO.read(new File(newimagepath)); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } BufferedImage copia = new BufferedImage(original.getWidth(), original.getHeight(), TYPE_BYTE_INDEXED); float[] floats = { 0, 0.125f, 0, 0.125f, 0.5f, 0.125f, 0, 0.125f, 0, }; BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, floats)); op.filter(original, copia); copia = copia.getSubimage(x, y, w, h); Graphics2D g2d = nueva.createGraphics(); g2d.drawImage(copia, x, y, null); //g2d.drawImage(copia, x, y, w, h, null); File output = new File(newimagepath); try { ImageIO.write(nueva, "png", output); } catch (IOException ex) { Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex); } postSC(); }
From source file:eu.udig.style.advanced.points.PointStyleManager.java
private TableViewer createStylesTableViewer(Composite parent) { final StyleFilter filter = new StyleFilter(); final Text searchText = new Text(parent, SWT.BORDER | SWT.SEARCH); searchText.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL)); searchText.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent ke) { filter.setSearchText(searchText.getText()); stylesViewer.refresh();//from w w w . ja va 2 s .c o m } }); stylesViewer = new TableViewer(parent, SWT.SINGLE | SWT.BORDER); Table table = stylesViewer.getTable(); GridData tableGD = new GridData(SWT.FILL, SWT.FILL, true, true); tableGD.heightHint = 200; table.setLayoutData(tableGD); stylesViewer.addFilter(filter); stylesViewer.setContentProvider(new IStructuredContentProvider() { public Object[] getElements(Object inputElement) { if (inputElement instanceof List<?>) { List<?> styles = (List<?>) inputElement; StyleWrapper[] array = (StyleWrapper[]) styles.toArray(new StyleWrapper[styles.size()]); return array; } return null; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); stylesViewer.setLabelProvider(new LabelProvider() { public Image getImage(Object element) { if (element instanceof StyleWrapper) { StyleWrapper styleWrapper = (StyleWrapper) element; List<FeatureTypeStyleWrapper> featureTypeStyles = styleWrapper .getFeatureTypeStylesWrapperList(); int iconSize = 48; BufferedImage image = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (FeatureTypeStyleWrapper featureTypeStyle : featureTypeStyles) { List<RuleWrapper> rulesWrapperList = featureTypeStyle.getRulesWrapperList(); BufferedImage tmpImage = Utilities.pointRulesWrapperToImage(rulesWrapperList, iconSize, iconSize); g2d.drawImage(tmpImage, 0, 0, null); } g2d.dispose(); Image convertToSWTImage = AWTSWTImageUtils.convertToSWTImage(image); return convertToSWTImage; } return null; } public String getText(Object element) { if (element instanceof StyleWrapper) { StyleWrapper styleWrapper = (StyleWrapper) element; String styleName = styleWrapper.getName(); if (styleName == null || styleName.length() == 0) { styleName = Utilities.DEFAULT_STYLENAME; styleName = Utilities.checkSameNameStyle(getStyles(), styleName); styleWrapper.setName(styleName); } return styleName; } return ""; //$NON-NLS-1$ } }); stylesViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); if (!(selection instanceof IStructuredSelection)) { return; } IStructuredSelection sel = (IStructuredSelection) selection; if (sel.isEmpty()) { return; } Object selectedItem = sel.getFirstElement(); if (selectedItem == null) { // unselected, show empty panel return; } if (selectedItem instanceof StyleWrapper) { currentSelectedStyleWrapper = (StyleWrapper) selectedItem; } } }); return stylesViewer; }
From source file:edu.harvard.i2b2.analysis.ui.WaitPanel.java
@Override public void paintComponent(Graphics comp) { Graphics2D comp2D = (Graphics2D) comp; // height = getSize().height - imgHeight; // if (yPosition == -1) // yPosition = height - 20; // int cur = timer.getElapsedTime(); log.debug("In paint drawtime: " + drawtime); log.debug("In paint elapsed time: " + elapsedTime); if (drawtime == elapsedTime) { candraw = true;/*from w w w . j a va2 s.co m*/ } if (img != null && candraw) { // elapsedTime = cur; comp2D.drawImage(img, xPosition, yPosition, this); drawtime++; candraw = false; } }
From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java
private void drawLegendLine(Graphics2D g2, int verticalOffset, double horizontalNumberOffset, Color col, String txt, String numberText, boolean textIsPlural, boolean withSubSegment, String subSegmentText, String subNumberText, boolean subTextIsPlural) { int left = 620; // col == null --> total --> kein Rechteck if (col != null) { g2.drawImage(keyShadow.getImage(), left, 30 + verticalOffset, keyShadow.getImageObserver()); g2.setColor(col);/*from w w w. j a va 2s. c om*/ g2.fillRect(left + 13, 37 + verticalOffset, 45, 45); if (withSubSegment) { Polygon p = new Polygon(new int[] { left + 13 + 45, left + 13 + 45, left + 13 }, new int[] { verticalOffset + 37, verticalOffset + 37 + 45, verticalOffset + 37 + 45 }, 3); g2.setColor(col.darker()); g2.fillPolygon(p); } } g2.setColor(Color.BLACK); StringBuffer sb = new StringBuffer(numberText); sb.append(" ").append(plural(textIsPlural, txt)); if (withSubSegment) { sb.append(" with "); sb.append(subNumberText); sb.append(" "); sb.append(plural(subTextIsPlural, subSegmentText)); } g2.drawString(sb.toString(), (int) (left + 80 + horizontalNumberOffset), 30 + 41 + verticalOffset); }
From source file:Composite.java
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; Dimension d = getSize();//from ww w.jav a2s.co m int w = d.width; int h = d.height; BufferedImage buffImg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D gbi = buffImg.createGraphics(); g2.setColor(Color.white); g2.fillRect(0, 0, d.width, d.height); int rectx = w / 4; int recty = h / 4; gbi.setColor(new Color(0.0f, 0.0f, 1.0f, 1.0f)); gbi.fill(new Rectangle2D.Double(rectx, recty, 150, 100)); gbi.setColor(new Color(1.0f, 0.0f, 0.0f, 1.0f)); gbi.setComposite(ac); gbi.fill(new Ellipse2D.Double(rectx + rectx / 2, recty + recty / 2, 150, 100)); g2.drawImage(buffImg, null, 0, 0); }