/** constructor */ public DanceQueuePanel() { // flow layout setLayout(new FlowLayout()); // uses buffer to draw arrows based on queues in an array myImage = new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB); myBuffer = myImage.getGraphics(); // uses timer to queue buffer changes time = 0; timer = new Timer(5, new Listener()); timer.start(); setFocusable(true); // picks instructions based on song & level if (Danceoff.getSong() == -1 && Danceoff.getDifficulty() == 0) { arrows = new Arrow[] {new UpArrow(1000), new DownArrow(2000), new LeftArrow(3000)}; } // setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK, 3), // "DanceQueuePanel")); // load images for arrows rightArrowImg = null; leftArrowImg = null; upArrowImg = null; downArrowImg = null; try { rightArrowImg = ImageIO.read(new File("arrowB right.png")); leftArrowImg = ImageIO.read(new File("arrowB left.png")); upArrowImg = ImageIO.read(new File("arrowB up copy.png")); downArrowImg = ImageIO.read(new File("arrowB down.png")); } catch (IOException e) { warn("YOU FAIL", e); System.exit(2); } }
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 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; }
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(); }
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 static BufferedImage tileImage(BufferedImage im, int width, int height) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); int transparency = Transparency.OPAQUE; // Transparency.BITMASK; BufferedImage compatible = gc.createCompatibleImage(width, height, transparency); Graphics2D g = (Graphics2D) compatible.getGraphics(); g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight()))); g.fillRect(0, 0, width, height); return compatible; }
public void generarFondo(Component componente) { Rectangle areaDibujo = this.getBounds(); BufferedImage tmp; GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); tmp = gc.createCompatibleImage(areaDibujo.width, areaDibujo.height, BufferedImage.TRANSLUCENT); Graphics2D g2d = (Graphics2D) tmp.getGraphics(); g2d.setColor(new Color(55, 55, 255, 165)); g2d.fillRect(0, 0, areaDibujo.width, areaDibujo.height); fondo = tmp; }
/** * Internal utility method that creates a new icon. Called after the user selects a new color, or * when the size of the icon changes. */ private void updateIcon() { BufferedImage image = new BufferedImage(iconWidth, iconHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = (Graphics2D) image.getGraphics(); g2d.setColor(this.color); // turn antialiasing off g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); // we want fast rendering g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2d.fillRect(0, 0, iconWidth, iconHeight); ImageIcon imageIcon = new ImageIcon(image); this.setIcon(imageIcon); g2d.dispose(); }
public GamePanel() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); // Create an image that does not support transparency backBufferImage = gc.createCompatibleImage( TopDownShooter_Main.screenWidth, TopDownShooter_Main.screenHeight, Transparency.OPAQUE); backBuffer = backBufferImage.getGraphics(); player = new Player(new Point(750, 750)); map = Map.getInstance(); map.loadWorld("World 1"); viewScreen = ViewScreen.getInstance(); collisionManager = CollisionManager.getInstance(); SwingUtilities.invokeLater( new Runnable() { // The GUI needs to be added to the JPanel at a later time, since there is // no way to know the size of this panel yet. public void run() { viewScreen.setSize( new Rectangle( new Point(0, 0), new Dimension( GamePanel.this.getWidth(), GamePanel.this .getHeight()))); // Size the ViewScreen to the actual dimensions of the // viewable area now that we know them viewScreen.CenterOnObject(player.getBoundingBox()); } }); this.setFocusable(true); this.addKeyListener(player); new Timer(16, this).start(); // Master game timer }
protected void filePNG() { JFileChooser chooser = null; File pngFile = null; if (currentFile == null) { chooser = new JFileChooser(startDirectory); } else { pngFile = new File(currentFile.getName() + ".png"); chooser = new JFileChooser(pngFile); if (!currentFile.isDirectory()) { chooser.setSelectedFile(currentFile); } } if (pngFile == null) return; try { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB); paint(image.getGraphics()); ImageIO.write(image, "png", pngFile); } catch (Exception e) { } return; /* JFileChooser chooser = null; File pngFile = null; if (currentFile == null) { chooser = new JFileChooser(startDirectory); } else { pngFile = new File(currentFile.getName()+".png"); chooser = new JFileChooser(pngFile); if (!currentFile.isDirectory()) { chooser.setSelectedFile(currentFile); } } int returnVal = chooser.showSaveDialog(gw); if (returnVal == JFileChooser.APPROVE_OPTION) { File pngFile = chooser.getSelectedFile(); int maxX = Integer.MIN_VALUE; int minX = Integer.MAX_VALUE; int maxY = Integer.MIN_VALUE; int minY = Integer.MAX_VALUE; while(Node node : getNodes()) { if(node.getX() > maxX) { maxX = node.getX(); } if(node.getX() < minX) { minX = node.getX(); } if(node.getY() > maxY) { maxY = node.getY(); } if(node.getY() < minY) { minY = node.getY(); } } BufferedImage image = new BufferedImage(maxX-minX+50,maxY-minY+50,BufferedImage.TYPE_INT_RGB); ImageIO.write(image,"png",pngFile); } */ }
// Although it presently returns a boolean, that was only needed // during my aborted attempted at animated graphics primitives. // Until those become a reality the boolean value returned by this // routine is unnecessary public boolean animate(int sAt, boolean forward) { int x; LinkedList lt = null; animation_done = true; // May be re-set in paintComponent via indirect paintImmediately call at end // Was used in aborted attempted to // introduce animated primitives. Now // it's probably excess baggage that // remains because I still have hopes // of eventually having animated // primitives if (getSize().width != 0 && getSize().height != 0) { my_width = getSize().width; // set dimensions my_height = getSize().height; } else { my_width = GaigsAV.preferred_width; // set dimensions my_height = GaigsAV.preferred_height; } // First capture the new image in a buffer called image2 SnapAt = sAt; BufferedImage image2 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) image2.getGraphics(); // need a separate object each time? g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fillRect(0, 0, my_width, my_height); // Set horizoff and vertoff to properly center the visualization in the // viewing window. This is not quite perfect because visualizations // that are not properly centered within their [0,1] localized // coordinates will not be perfectly centered, but it is much better // than it was previously. if (no_mouse_drag) { horizoff = (my_width - GaigsAV.preferred_width) / 2; vertoff = (my_height - GaigsAV.preferred_height) / 2; } list_of_snapshots.reset(); x = 0; lt = new LinkedList(); while (x < SnapAt && list_of_snapshots.hasMoreElements()) { lt = (LinkedList) list_of_snapshots.nextElement(); x++; } lt.reset(); animation_done = true; // System.out.println("before loop " + horizoff); while (lt.hasMoreElements()) { obj tempObj = (obj) lt.nextElement(); animation_done = animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff)); // System.out.println("in loop"); } // Next capture the image we are coming from in a buffer called image1 SnapAt = (forward ? sAt - 1 : sAt + 1); BufferedImage image1 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB); Graphics2D g1 = (Graphics2D) image1.getGraphics(); // need a separate object each time? g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g1.setColor(Color.WHITE); g1.fillRect(0, 0, my_width, my_height); // Set horizoff and vertoff to properly center the visualization in the // viewing window. This is not quite perfect because visualizations // that are not properly centered within their [0,1] localized // coordinates will not be perfectly centered, but it is much better // than it was previously. if (no_mouse_drag) { horizoff = (my_width - GaigsAV.preferred_width) / 2; vertoff = (my_height - GaigsAV.preferred_height) / 2; } list_of_snapshots.reset(); x = 0; lt = new LinkedList(); while (x < SnapAt && list_of_snapshots.hasMoreElements()) { lt = (LinkedList) list_of_snapshots.nextElement(); x++; } lt.reset(); animation_done = true; // System.out.println("before loop " + horizoff); while (lt.hasMoreElements()) { obj tempObj = (obj) lt.nextElement(); animation_done = animation_done && (tempObj.execute(g1 /*offscreen*/, zoom, vertoff, horizoff)); // System.out.println("in loop"); } // Now slide from image1 to image2 // From the gaff Visualizer by Chris Gaffney // double step = 4; // Adjust this for more/less granularity between images double step = 40; // Adjust this for more/less granularity between images Image buffer = getGraphicsConfiguration().createCompatibleVolatileImage(my_width, my_height); Graphics2D g2d = (Graphics2D) buffer.getGraphics(); AffineTransform trans = AffineTransform.getTranslateInstance(step * (forward ? -1 : 1), 0); // AffineTransform orig = g2d.getTransform(); Shape mask = createMask(my_width, my_height); for (double i = 0; i < my_width; i += step) { if (i + step > my_width) // last time through loop, so adjust transform trans = AffineTransform.getTranslateInstance(((double) (my_width - i)) * (forward ? -1 : 1), 0); g2d.transform(trans); g2d.drawImage(image1, 0, 0, this); g2d.setColor(Color.BLACK); g2d.fill(mask); AffineTransform last = g2d.getTransform(); g2d.transform(AffineTransform.getTranslateInstance(my_width * (-1 * (forward ? -1 : 1)), 0)); g2d.drawImage(image2, 0, 0, this); g2d.setColor(Color.BLACK); g2d.fill(mask); g2d.setTransform(last); this.my_image = buffer; repaint(); try { Thread.sleep(10); } catch (InterruptedException e) { } } Image b = getGraphicsConfiguration().createCompatibleImage(my_width, my_height); b.getGraphics().drawImage(buffer, 0, 0, null); this.my_image = b; return animation_done; }
// Although it presently returns a boolean, that was only needed // during my aborted attempted at animated graphics primitives. // Until those become a reality the boolean value returned by this // routine is unnecessary public /*synchronized*/ boolean execute(int sAt) { // The commented-out variables below are remnants from legacy // code -- they appear to be no longer needed. // String urlTemp=""; // int z=0; // int idx; // int urlid; // boolean showURL=false; animation_done = true; // May be re-set in paintComponent via indirect paintImmediately call at end // Was used in abored attempted to // introduce animated primitives. Now // it's probably excess baggage that // remains because I still have hopes // of eventually having animated // primitives SnapAt = sAt; if (getSize().width != 0 && getSize().height != 0) { my_width = getSize().width; // set dimensions my_height = getSize().height; } else { my_width = GaigsAV.preferred_width; // set dimensions my_height = GaigsAV.preferred_height; } BufferedImage buff = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = (Graphics2D) buff.getGraphics(); // need a separate object each time? g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setColor(Color.WHITE); g2.fillRect(0, 0, my_width, my_height); // Set horizoff and vertoff to properly center the visualization in the // viewing window. This is not quite perfect because visualizations // that are not properly centered within their [0,1] localized // coordinates will not be perfectly centered, but it is much better // than it was previously. // if(no_mouse_drag){ // if(first_paint_call){ // // horizoff = (my_width - (int)(0.25 * my_width) - // // GaigsAV.preferred_width) / 2; // horizoff = (my_width - GaigsAV.preferred_width) / 2; // first_paint_call = false; // }else{ // horizoff = (my_width - GaigsAV.preferred_width) / 2; // no_mouse_drag = false; // } // } if (no_mouse_drag) { horizoff = (my_width - GaigsAV.preferred_width) / 2; vertoff = (my_height - GaigsAV.preferred_height) / 2; } int x; list_of_snapshots.reset(); x = 0; LinkedList lt = new LinkedList(); while (x < SnapAt && list_of_snapshots.hasMoreElements()) { lt = (LinkedList) list_of_snapshots.nextElement(); x++; } lt.reset(); animation_done = true; // System.out.println("before loop " + horizoff); while (lt.hasMoreElements()) { obj tempObj = (obj) lt.nextElement(); animation_done = animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff)); // System.out.println("in loop"); } Shape mask = createMask(buff.getWidth(), buff.getHeight()); g2.setColor(Color.BLACK); g2.fill(mask); my_image = buff; repaint(); return animation_done; }
private BufferedImage getSpecificImage( int x, int y, int w, int h, int imgIndexX, int imgIndexY, BufferedImage buffImg, int zoom, int cachedZoom, GMapListener listener, boolean localFilesOnly) { int xIndex = x / GDataSource.sourceSize.width; int yIndex = y / GDataSource.sourceSize.height; xIndex += imgIndexX; yIndex += imgIndexY; BufferedImage image = null; if (!localFilesOnly || getGDataSource().isCached(xIndex, yIndex, zoom)) image = getIndexedImage(xIndex, yIndex, zoom, cachedZoom, listener); int xCoord = x % GDataSource.sourceSize.width; int yCoord = y % GDataSource.sourceSize.height; // Checks for invalid xCoord and yCoord if (xCoord < 0) { xCoord = 0; } if (yCoord < 0) { yCoord = 0; } // get info about the image Dimension imageSize = new Dimension(getGDataSource().sourceSize.width, getGDataSource().sourceSize.height); // find the width of what we CAN paint int initPaintWidth = imageSize.width - xCoord; int initPaintHeight = imageSize.height - yCoord; int paintWidth = initPaintWidth; int paintHeight = initPaintHeight; int rowImages = numOfRows(x, y, h, zoom, cachedZoom); int colImages = numOfCols(x, y, w, zoom, cachedZoom); if (imgIndexX >= colImages || imgIndexY >= rowImages) { return null; } int xImage = 0; int yImage = 0; int xInitCoord = xCoord; int yInitCoord = yCoord; if (imgIndexX > 0) { xImage = initPaintWidth + (imgIndexX - 1) * imageSize.width; xCoord = 0; if (imgIndexX < (colImages - 1)) { paintWidth = imageSize.width; } else { paintWidth = w - ((colImages - 2) * imageSize.width) - (imageSize.width - xInitCoord); } } if (imgIndexY > 0) { yImage = initPaintHeight + (imgIndexY - 1) * imageSize.height; yCoord = 0; if (imgIndexY < (rowImages - 1)) { paintHeight = imageSize.height; } else { paintHeight = h - ((rowImages - 2) * imageSize.height) - (imageSize.height - yInitCoord); } } if (buffImg != null) { Graphics2D g = (Graphics2D) buffImg.getGraphics(); if (image != null) { // System.out.println(xCoord + ":" + yCoord + ":" + paintWidth + ":" + paintHeight); g.drawImage( image.getSubimage(xCoord, yCoord, paintWidth, paintHeight), xImage, yImage, paintWidth, paintHeight, null); } else { Composite originalComposite = g.getComposite(); g.setComposite(opacity40); g.setColor(Color.BLACK); g.fillRect(xImage, yImage, paintWidth, paintHeight); g.setComposite(originalComposite); } } return buffImg; }
public void actionPerformed(ActionEvent e) { if (e.getSource() == b) { JFrame frame2 = new JFrame(); JFileChooser chooser = new JFileChooser("."); int option = chooser.showOpenDialog( frame2); // parentComponent must a component like JFrame, JDialog... if (option == JFileChooser.APPROVE_OPTION) { File selectedFile = chooser.getSelectedFile(); path = selectedFile.getAbsolutePath(); } try { loadImage(); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } } else if (e.getSource() == c) { gaussianBlur(); // filtered = grayscale.filter(filtered, null); sobel(); // thinImage(); nonMax(); float lowThreshold = 2.5f; float highThreshold = 7.5f; int low = Math.round(lowThreshold * MAGNITUDE_SCALE); int high = Math.round(highThreshold * MAGNITUDE_SCALE); performHysteresis(low, high); thresholdEdges(); writeEdges(data); Hough(); ImageIcon icon1 = new ImageIcon(res); lbl1.setIcon(icon1); ImageIcon icon2 = new ImageIcon(filtered); lbl2.setIcon(icon2); filterBtn.setSelected(true); } if (e.getSource() == findCircles) { try { accSize = Integer.parseInt(inputCircles.getText()); res = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = res.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); findMaxima(); ImageIcon icon1 = new ImageIcon(res); lbl1.setIcon(icon1); } catch (Exception err) { System.out.println("Not a valid integer"); } } else if (e.getSource() == filterBtn) { ImageIcon icon2 = new ImageIcon(filtered); lbl2.setIcon(icon2); } else if (e.getSource() == sobelBtn) { ImageIcon icon2 = new ImageIcon(sobel); lbl2.setIcon(icon2); } else if (e.getSource() == nonMaxBtn) { ImageIcon icon2 = new ImageIcon(nonMax); lbl2.setIcon(icon2); } else if (e.getSource() == accumulator) { buildAccumulator(whichRadius.getValue()); } }