public Image getScreenshot() { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = image.getGraphics(); paint(g); g.dispose(); return image; }
public static void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { g = g.create(x, y, width, height); // corners TL.paintIcon(c, g, x, y); BL.paintIcon(c, g, x, y + height - BL.getIconHeight()); TR.paintIcon(c, g, x + width - TR.getIconWidth(), y); BR.paintIcon(c, g, x + width - BR.getIconWidth(), y + height - BR.getIconHeight()); // top and bottom lines int xOffset = x + TL.getIconWidth(); int stop = x + width - TR.getIconWidth(); int top = y; int bottom = y + height - B.getIconHeight(); g.setClip(xOffset, y, width - L.getIconWidth() - R.getIconWidth(), height); while (xOffset < stop) { T.paintIcon(c, g, xOffset, top); B.paintIcon(c, g, xOffset, bottom); xOffset += T.getIconWidth(); } // left and right lines int left = x; int right = x + width - R.getIconWidth(); int yOffset = y + T.getIconHeight(); stop = y + height - B.getIconHeight(); g.setClip(x, yOffset, width, height - T.getIconHeight() - B.getIconHeight()); while (yOffset < stop) { L.paintIcon(c, g, left, yOffset); R.paintIcon(c, g, right, yOffset); yOffset += L.getIconHeight(); } g.dispose(); }
public void clear() { Graphics g = this.image.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, this.image.getWidth(null), this.image.getHeight(null)); g.dispose(); repaint(); }
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (drawOverlay) { g = g.create(); AntialiasingManager.activateAntialiasing(g); try { // Paint a roll over fade out. FadeTracker fadeTracker = FadeTracker.getInstance(); float visibility = 0.0f; if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) { visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER); visibility /= 4; } else visibility = 0.5f; // Draw black overlay g.setColor(new Color(0.0f, 0.0f, 0.0f, visibility)); g.fillRoundRect(1, 1, width - 2, height - 2, 10, 10); // Draw arrow g.setColor(Color.WHITE); int[] arrowX = new int[] {width - 17, width - 7, width - 12}; int[] arrowY = new int[] {height - 12, height - 12, height - 7}; g.fillPolygon(arrowX, arrowY, arrowX.length); } finally { g.dispose(); } } }
public static BufferedImage copyImage(BufferedImage source) { BufferedImage b = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_BYTE_GRAY); Graphics g = b.getGraphics(); g.drawImage(source, 0, 0, null); g.dispose(); return b; }
/** This method creates the off-screen canvas and fills it with the current fill color. */ private void createOSC() { OSC = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); Graphics osg = OSC.getGraphics(); Color fillColor = new Color(0, 0, 0); fillColor = Color.WHITE; osg.setColor(fillColor); osg.fillRect(0, 0, getWidth(), getHeight()); osg.dispose(); }
private void scaleImage() { Image img = back.getScaledInstance(scx(back.getWidth()), scy(back.getHeight()), Image.SCALE_SMOOTH); back = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = back.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); }
private void drawLine(JComponent c, int x, int y) { _xedit = x; _yedit = y; Graphics g = c.getGraphics(); g.setColor(Color.BLACK); g.setXORMode(c.getBackground()); g.drawLine(_xdown, _ydown, _xedit, _yedit); g.dispose(); }
/** * Paint a background for all groups and a round blue border and background when a cell is * selected. * * @param g the <tt>Graphics</tt> object */ public void paintComponent(Graphics g) { Graphics g2 = g.create(); try { internalPaintComponent(g2); } finally { g2.dispose(); } super.paintComponent(g); }
private void replaceSurfaceData( int newBackBufferCount, BufferCapabilities newBackBufferCaps, boolean blit) { synchronized (surfaceDataLock) { final SurfaceData oldData = getSurfaceData(); surfaceData = platformWindow.replaceSurfaceData(); // TODO: volatile image // VolatileImage oldBB = backBuffer; BufferedImage oldBB = backBuffer; backBufferCount = newBackBufferCount; backBufferCaps = newBackBufferCaps; final Rectangle size = getSize(); if (getSurfaceData() != null && oldData != getSurfaceData()) { clearBackground(size.width, size.height); } if (blit) { blitSurfaceData(oldData, getSurfaceData()); } if (oldData != null && oldData != getSurfaceData()) { // TODO: drop oldData for D3D/WGL pipelines // This can only happen when this peer is being created oldData.flush(); } // TODO: volatile image // backBuffer = (VolatileImage)delegate.createBackBuffer(); backBuffer = (BufferedImage) platformWindow.createBackBuffer(); if (backBuffer != null) { Graphics g = backBuffer.getGraphics(); try { Rectangle r = getBounds(); if (g instanceof Graphics2D) { ((Graphics2D) g).setComposite(AlphaComposite.Src); } g.setColor(nonOpaqueBackground); g.fillRect(0, 0, r.width, r.height); if (g instanceof SunGraphics2D) { ((SunGraphics2D) g).constrain(0, 0, r.width, r.height, getRegion()); } if (!isTextured()) { g.setColor(getBackground()); g.fillRect(0, 0, r.width, r.height); } if (oldBB != null) { // Draw the old back buffer to the new one g.drawImage(oldBB, 0, 0, null); oldBB.flush(); } } finally { g.dispose(); } } } flushOnscreenGraphics(); }
@Override protected void paintTabBackground( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) { g = g.create(); try { internalPaintTabBackground(g, tabPlacement, tabIndex, x, y, w, h, isSelected); } finally { g.dispose(); } }
/** * Extracts the buffered image of some component * * @param myComponent the component for which the BufferedImage is required * @param region region to be captured * @return the BufferedImage which has the current condition of component * @throws IOException */ public static BufferedImage Get_Component_Image(Component myComponent, Rectangle region) throws IOException { BufferedImage img = new BufferedImage( myComponent.getWidth(), myComponent.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); myComponent.paint(g); g.dispose(); return img; }
public void paint(Graphics g) { putClientProperty("JTree.lineStyle", "None"); Graphics g1 = g.create(); g1.translate(0, -myVisibleRow * getRowHeight()); super.paint(g1); g1.dispose(); if (myBorder != null) { myBorder.paintBorder(this, g, 0, 0, myTreeTable.getWidth(), getRowHeight()); } }
public void paintImage(Graphics g) { final Rectangle b = getBounds(); final Graphics lG = g.create(b.x, b.y, b.width, b.height); try { lG.setColor(Color.red); doPaint(lG); } finally { lG.dispose(); } }
private static ImageIcon makeGrayImageIcon1(Image img) { BufferedImage source = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); Graphics g = source.createGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); ColorConvertOp colorConvert = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); BufferedImage destination = colorConvert.filter(source, null); return new ImageIcon(destination); }
/** * Finish a mouse drag operation. Nothing is done unless the current tool is a shape tool. For * shape tools, the user's shape is drawn to the off-screen canvas, making it a permanent part * of the picture, and then the repaint() method is called to show the modified picture on the * screen. */ @Override public void mouseReleased(MouseEvent evt) { dragging = false; if (SHAPE_TOOLS.contains(currentTool)) { Graphics g = OSC.getGraphics(); g.setColor(currentColor); putCurrentShape(g); g.dispose(); repaint(); } }
/** * Paint a background for all groups and a round blue border and background when a cell is * selected. * * @param g the <tt>Graphics</tt> object used for painting */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); g = g.create(); try { internalPaintComponent(g); } finally { g.dispose(); } }
/** * Prepare a buffer for the image, return if the canvas is ready Only need to call this when the * size of the canvas is changed, Since we automatically detect the size change in paint() only * call this on start */ public boolean newImgBuf() { Dimension sz = getSize(); if (sz.width == 0 || sz.height == 0) return false; // quit if the current image already has the right size if (img != null && imgG != null && sz.equals(imgSize)) return true; img = createImage(sz.width, sz.height); if (imgG != null) imgG.dispose(); imgG = img.getGraphics(); imgSize = sz; return true; }
private static ImageIcon makeRolloverIcon(ImageIcon srcIcon) { RescaleOp op = new RescaleOp(new float[] {1.2f, 1.2f, 1.2f, 1f}, new float[] {0f, 0f, 0f, 0f}, null); BufferedImage img = new BufferedImage( srcIcon.getIconWidth(), srcIcon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = img.getGraphics(); // g.drawImage(srcIcon.getImage(), 0, 0, null); srcIcon.paintIcon(null, g, 0, 0); g.dispose(); return new ImageIcon(op.filter(img, null)); }
public void loadImage() throws IOException { nonMax = ImageIO.read(new File(path)); width = nonMax.getWidth(); height = nonMax.getHeight(); rmax = width > height ? height / 2 : width / 2; accRMax = (rmax + offset - 1) / offset; whichRadius.setMaximum(accRMax); img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = img.getGraphics(); g.drawImage(nonMax, 0, 0, null); g.dispose(); res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); g = res.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); greyScale = copyImage(nonMax); ImageIcon icon = new ImageIcon(img); ImageIcon icon2 = new ImageIcon(greyScale); lbl1.setIcon(icon); lbl2.setIcon(icon2); }
public void dispose() { super.dispose(); if (mViewport != null) { mViewport.terminate(); mViewport = null; } setUniverse(null); if (mBackBufferGfx != null) { mBackBufferGfx.dispose(); } Logger.log("FramedViewportContainer terminated"); }
private static ImageIcon makeGrayImageIcon2(Image img) { int w = img.getWidth(null); int h = img.getHeight(null); BufferedImage destination = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_GRAY); Graphics g = destination.createGraphics(); //// g.setColor(Color.WHITE); // https://community.oracle.com/thread/1373262 Color to Grayscale to Binary // g.fillRect(0, 0, w, h); // need to pre-fill(alpha?) g.drawImage(img, 0, 0, null); g.dispose(); return new ImageIcon(destination); }
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { float size = this.stroke.getLineWidth(); if (size > 0.0f) { g = g.create(); if (g instanceof Graphics2D) { Graphics2D g2d = (Graphics2D) g; g2d.setStroke(this.stroke); g2d.setPaint(color != null ? color : c == null ? null : c.getForeground()); g2d.draw(new Rectangle2D.Float(x + size / 2, y + size / 2, width - size, height - size)); } g.dispose(); } }
public void paint(Graphics g) { super.paint(g); if (Game.gameState == GameState.LOADING) { if (highlightedString == 0) { g.setColor(Color.RED); g.drawString("Start Game", 100, 80); g.setColor(Color.GREEN); g.drawString("Continue Game", 100, 100); g.drawString("Options", 100, 120); } else if (highlightedString == 1) { g.setColor(Color.GREEN); g.drawString("Start Game", 100, 80); g.setColor(Color.RED); g.drawString("Continue Game", 100, 100); g.setColor(Color.GREEN); g.drawString("Options", 100, 120); } else if (highlightedString == 2) { g.setColor(Color.GREEN); g.drawString("Start Game", 100, 80); g.setColor(Color.GREEN); g.drawString("Continue Game", 100, 100); g.setColor(Color.RED); g.drawString("Options", 100, 120); } } if (Game.gameState == GameState.PLAYING) { Graphics2D g2d = (Graphics2D) g; g2d.drawImage(player.getImage(), player.getX(), player.getY(), this); ArrayList ms = player.getMissiles(); g.drawString("Bug Count: " + Bug.bugArrayList.size(), 270, 30); g.drawString("Player Score: " + Mech.mechHashMap.get(0).getScore(), 270, 60); g.drawString("Player Lives: " + Mech.mechHashMap.get(0).getLives(), 270, 90); g.drawString("Weapon Selected: " + Mech.mechHashMap.get(0).weaponSelected, 270, 120); for (int i = 0; i < ms.size(); i++) { Missile m = (Missile) ms.get(i); g2d.drawImage(m.getImage(), m.getX(), m.getY(), this); } for (Bug bug : Bug.bugArrayList) { g2d.drawImage(bug.image, bug.x, bug.y, this); System.out.println("draw bug"); System.out.println("Bug Count;" + Bug.bugArrayList.size()); bug.move(); } } else if (Game.gameState == GameState.GAMEOVER) { g.drawString("GAME OVER!", 100, 100); } Toolkit.getDefaultToolkit().sync(); g.dispose(); }
public static BufferedImage componentToImage(Component component, Rectangle region) { BufferedImage img = new BufferedImage( component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE); Graphics g = img.getGraphics(); g.setColor(component.getForeground()); g.setFont(component.getFont()); component.paintAll(g); g.dispose(); if (region == null) { return img; } return img.getSubimage(region.x, region.y, region.width, region.height); }
/** * When the ERASE or SMUDGE tools are used and the mouse jumps from (x1,y1) to (x2,y2), the tool * has to be applied to a line of pixel positions between the two points in order to cover the * entire line that the mouse moves along. The change is made to the off-screen canvas, and * repaint() is called to copy the changes to the screen. */ void applyToolAlongLine(int x1, int y1, int x2, int y2) { Graphics g = OSC.getGraphics(); g.setColor(fillColor); // (for ERASE only) int w = OSC.getWidth(); // (for SMUDGE only) int h = OSC.getHeight(); // (for SMUDGE only) int dist = Math.max(Math.abs(x2 - x1), Math.abs(y2 - y1)); // dist is the number of points along the line from // (x1,y1) to (x2,y2) at which the tool will be applied. double dx = (double) (x2 - x1) / dist; double dy = (double) (y2 - y1) / dist; for (int d = 1; d <= dist; d++) { // Apply the tool at one of the points (x,y) along the // line from (x1,y1) to (x2,y2). int x = (int) Math.round(x1 + dx * d); int y = (int) Math.round(y1 + dy * d); if (currentTool == Tool.ERASE) { // Erase a 10-by-10 block of pixels around (x,y) g.fillRect(x - 5, y - 5, 10, 10); repaint(x - 5, y - 5, 10, 10); } else { // For the SMUDGE tool, blend some of the color from // the smudgeRed, smudgeGreen, and smudgeBlue arrays // into the pixels in a 7-by-7 block around (x,y), and // vice versa. The effect is to smear out the color // of pixels that are visited by the tool. for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { int r = y + j - 3; int c = x + i - 3; if (!(r < 0 || r >= h || c < 0 || c >= w || smudgeRed[i][j] == -1)) { int curCol = OSC.getRGB(c, r); int curRed = (curCol >> 16) & 0xFF; int curGreen = (curCol >> 8) & 0xFF; int curBlue = curCol & 0xFF; int newRed = (int) (curRed * 0.7 + smudgeRed[i][j] * 0.3); int newGreen = (int) (curGreen * 0.7 + smudgeGreen[i][j] * 0.3); int newBlue = (int) (curBlue * 0.7 + smudgeBlue[i][j] * 0.3); int newCol = newRed << 16 | newGreen << 8 | newBlue; OSC.setRGB(c, r, newCol); smudgeRed[i][j] = curRed * 0.3 + smudgeRed[i][j] * 0.7; smudgeGreen[i][j] = curGreen * 0.3 + smudgeGreen[i][j] * 0.7; smudgeBlue[i][j] = curBlue * 0.3 + smudgeBlue[i][j] * 0.7; } } } repaint(x - 3, y - 3, 7, 7); } } g.dispose(); }
/** Prints the drawing. */ public void print() { tool().deactivate(); PrintJob printJob = getToolkit().getPrintJob(this, "Print Drawing", null); if (printJob != null) { Graphics pg = printJob.getGraphics(); if (pg != null) { ((StandardDrawingView) view()).printAll(pg); pg.dispose(); // flush page } printJob.end(); } tool().activate(); }
/** @{inheritDoc} */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); g = g.create(); try { AntialiasingManager.activateAntialiasing(g); g.setColor(Color.DARK_GRAY); g.fillRoundRect(0, 0, this.getWidth(), this.getHeight(), 10, 10); } finally { g.dispose(); } }
// private BufferedImage makeBI(String str) { // BufferedImage image; // try { // image = ImageIO.read(getClass().getResource(str)); // } catch (IOException ioe) { // ioe.printStackTrace(); // return null; // } // return image; // } private static int[] getData(ImageIcon imageIcon, int w, int h) { Image img = imageIcon.getImage(); BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = image.createGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); return ((DataBufferInt) (image.getRaster().getDataBuffer())).getData(); // int[] pixels = new int[w * h]; // try { // new PixelGrabber(image, 0, 0, width, height, pixels, 0, width).grabPixels(); // } catch (InterruptedException ex) { // ex.printStackTrace(); // } // return pixels; }
private void paintScreen() // use active rendering to put the buffered image on-screen { Graphics g; try { g = this.getGraphics(); if ((g != null) && (dbImage != null)) g.drawImage(dbImage, 0, 0, null); // Sync the display on some systems. // (on Linux, this fixes event queue problems) Toolkit.getDefaultToolkit().sync(); g.dispose(); } catch (Exception e) { System.out.println("Graphics context error: " + e); } } // end of paintScreen()