/** Creates a new instance of IDEJRManFramebufferImpl */ public IDEJRManFramebufferImpl(String name, BufferedImage image) { super("JRMan rendered: " + name, true, true, true, true); this.name = name; save.setEnabled(false); imagePanel.setImage(image); imagePanel.addToolbarAction(save); if (image.getType() == BufferedImage.TYPE_INT_ARGB || image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) { imagePanel.setShowTransparencyPattern(true); } getRootPane().setDoubleBuffered(false); getContentPane().add(imagePanel); pack(); ImageResource images = ImageResource.getInstance(); // set the frame icon setFrameIcon(images.getJrMan()); // add this to the IDE desktop MainMenuEventHandlers.getInstance(null) .getIdeInstance() .getWorkspaceDesktop() .addInternalFrame(this, true); }
/** * Save onscreen image to file - suffix must be png, jpg, or gif. * * @param filename the name of the file with one of the required suffixes */ public static void save(String filename) { File file = new File(filename); String suffix = filename.substring(filename.lastIndexOf('.') + 1); // png files if (suffix.toLowerCase().equals("png")) { try { ImageIO.write(onscreenImage, suffix, file); } catch (IOException e) { e.printStackTrace(); } } // need to change from ARGB to RGB for jpeg // reference: // http://archives.java.sun.com/cgi-bin/wa?A2=ind0404&L=java2d-interest&D=0&P=2727 else if (suffix.toLowerCase().equals("jpg")) { WritableRaster raster = onscreenImage.getRaster(); WritableRaster newRaster; newRaster = raster.createWritableChild(0, 0, width, height, 0, 0, new int[] {0, 1, 2}); DirectColorModel cm = (DirectColorModel) onscreenImage.getColorModel(); DirectColorModel newCM = new DirectColorModel( cm.getPixelSize(), cm.getRedMask(), cm.getGreenMask(), cm.getBlueMask()); BufferedImage rgbBuffer = new BufferedImage(newCM, newRaster, false, null); try { ImageIO.write(rgbBuffer, suffix, file); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("Invalid image file type: " + suffix); } }
// buffered images are just better. protected static BufferedImage imageToBufferedImage(Image img) { BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.drawImage(img, null, null); return bi; }
private void paintToImage( final BufferedImage img, final int x, final int y, final int width, final int height) { // clear the prior image Graphics2D imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.Clear); imgG.setColor(Color.black); imgG.fillRect(0, 0, width + blur * 2, height + blur * 2); final int adjX = (int) (x + blur + offsetX + (insets.left * distance)); final int adjY = (int) (y + blur + offsetY + (insets.top * distance)); final int adjW = (int) (width - (insets.left + insets.right) * distance); final int adjH = (int) (height - (insets.top + insets.bottom) * distance); // let the delegate paint whatever they want to be blurred imgG.setComposite(AlphaComposite.DstAtop); if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); // blur the prior image back into the same pixels imgG = (Graphics2D) img.getGraphics(); imgG.setComposite(AlphaComposite.DstAtop); imgG.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); imgG.setRenderingHint( RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); imgG.drawImage(img, blurOp, 0, 0); if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH); imgG.dispose(); }
/** * Returns the specified image as icon. * * @param name name of icon * @return icon */ public static ImageIcon icon(final String name) { ImageIcon ii = ICONS.get(name); if (ii != null) return ii; Image img; if (GUIConstants.scale > 1) { // choose large image or none final URL url = GUIConstants.large() ? BaseXImages.class.getResource("/img/" + name + "_32.png") : null; if (url == null) { // resize low-res image if no hi-res image exists img = get(url(name)); final int w = (int) (img.getWidth(null) * GUIConstants.scale); final int h = (int) (img.getHeight(null) * GUIConstants.scale); final BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); final Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.drawImage(img, 0, 0, w, h, null); g2.dispose(); img = tmp; } else { img = get(url); } } else { img = get(name); } ii = new ImageIcon(img); ICONS.put(name, ii); return ii; }
private void gameRender() { if (dbImage == null) { dbImage = createImage(PWIDTH, PHEIGHT); if (dbImage == null) { System.out.println("dbImage is null"); return; } else dbg = dbImage.getGraphics(); } // draw a white background dbg.setColor(Color.white); dbg.fillRect(0, 0, PWIDTH, PHEIGHT); // draw the game elements: order is important ribsMan.display(dbg); // the background ribbons bricksMan.display(dbg); // the bricks jack.drawSprite(dbg); // the sprites fireball.drawSprite(dbg); if (showExplosion) // draw the explosion (in front of jack) dbg.drawImage(explosionPlayer.getCurrentImage(), xExpl, yExpl, null); reportStats(dbg); if (gameOver) gameOverMessage(dbg); if (showHelp) // draw the help at the very front (if switched on) dbg.drawImage( helpIm, (PWIDTH - helpIm.getWidth()) / 2, (PHEIGHT - helpIm.getHeight()) / 2, null); } // end of gameRender()
public SimpleWhiteboardPanel(int width, int height) { this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = this.image.getGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, image.getWidth(), image.getHeight()); this.setFocusable(true); }
public Image getScreenshot() { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = image.getGraphics(); paint(g); g.dispose(); return image; }
public void generarFondo(Component componente) { boolean dibujarFondo = false; Rectangle med = this.getBounds(); Rectangle areaDibujo = this.getBounds(); BufferedImage tmp; GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); if (Principal.fondoBlur) { dibujarFondo = true; } if (dibujarFondo) { JRootPane root = SwingUtilities.getRootPane(this); blurBuffer = GraphicsUtilities.createCompatibleImage(Principal.sysAncho, Principal.sysAlto); Graphics2D g2 = blurBuffer.createGraphics(); g2.setClip(med); blurBuffer = blurBuffer.getSubimage(med.x, med.y, med.width, med.height); ((Escritorio) Principal.getEscritorio()).getFrameEscritorio().paint(g2); g2.dispose(); backBuffer = blurBuffer; // blurBuffer = toGrayScale(blurBuffer); blurBuffer = GraphicsUtilities.createThumbnailFast(blurBuffer, getWidth() / 2); blurBuffer = new GaussianBlurFilter(4).filter(blurBuffer, null); g2 = (Graphics2D) blurBuffer.getGraphics(); g2.setColor(new Color(0, 0, 0, 195)); g2.fillRect(0, 0, Principal.sysAncho, Principal.sysAlto); listo = true; } }
private static BufferedImage makeBufferedImage(Icon icon, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, (w - icon.getIconWidth()) / 2, (h - icon.getIconWidth()) / 2); g.dispose(); return image; }
public static void saveJPG(Image img, String s) { BufferedImage bi = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB); Graphics2D g2 = bi.createGraphics(); g2.drawImage(img, null, null); FileOutputStream out = null; try { out = new FileOutputStream(s); } catch (java.io.FileNotFoundException io) { System.out.println("File Not Found"); } JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi); param.setQuality(0.5f, false); encoder.setJPEGEncodeParam(param); try { encoder.encode(bi); out.close(); } catch (java.io.IOException io) { System.out.println("IOException"); } }
/** paint the canvas into a image file of given width and height */ public void writeToImage(String s, int w, int h) { String ext; File f; try { ext = s.substring(s.lastIndexOf(".") + 1); f = new File(s); } catch (Exception e) { System.out.println(e); return; } if (!ext.equals("jpg") && !ext.equals("png")) { System.out.println("Cannot write to file: Illegal extension " + ext); return; } boolean opq = true; if (theOpaque != null) opq = theOpaque; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setBackground(Color.white); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1)); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); doBuffer(g2, true, new Rectangle(0, 0, w, h)); try { ImageIO.write(image, ext, f); } catch (Exception e) { System.out.println(e); } }
public synchronized void paint(Graphics g) { if (needToStartThread) { totalDrawTime = 0; counter = 0; needToStartThread = false; startThread(beginAngle, endAngle); if (firstImage == null) { firstImage = createImageFromComponent(component1); } if (secondImage == null) { secondImage = createImageFromComponent(component2); } } if (firstImage == null || secondImage == null) return; Graphics2D g2d = (Graphics2D) g; int ww = firstImage.getWidth(); int hh = firstImage.getHeight(); { BufferedImage currImage = null; int[] currPixels = null; int w = firstImage.getWidth(); int offset = (int) (w * angle / 180); if (offset < 0) offset = 0; if (offset > w) offset = w; long beforeDraw = System.currentTimeMillis(); g2d.drawImage(firstImage, null, 0, 0); g2d.drawImage(secondImage, null, w - offset, 0); totalDrawTime += (System.currentTimeMillis() - beforeDraw); counter++; } }
public void saveFrametoPNG(String filename) { final int frameWidth = _canvas.getWidth(); final int frameHeight = _canvas.getHeight(); final ByteBuffer pixelsRGB = Direct.newByteBuffer(frameWidth * frameHeight * 3); _canvas.runWithContext( new Runnable() { public void run() { // glPushAttrib(GL_PIXEL_MODE_BIT); glReadBuffer(GL_BACK); glPixelStorei(GL_PACK_ALIGNMENT, 1); glReadPixels(0, 0, frameWidth, frameHeight, GL_RGB, GL_UNSIGNED_BYTE, pixelsRGB); // glPopAttrib(); } }); int[] pixelInts = new int[frameWidth * frameHeight]; int p = frameWidth * frameHeight * 3; int q; // Index into ByteBuffer int i = 0; // Index into target int[] int w3 = frameWidth * 3; // Number of bytes in each row for (int row = 0; row < frameHeight; row++) { p -= w3; q = p; for (int col = 0; col < frameWidth; col++) { int iR = pixelsRGB.get(q++); int iG = pixelsRGB.get(q++); int iB = pixelsRGB.get(q++); pixelInts[i++] = 0xFF000000 | ((iR & 0x000000FF) << 16) | ((iG & 0x000000FF) << 8) | (iB & 0x000000FF); } } // Create a new BufferedImage from the pixeldata. BufferedImage bufferedImage = new BufferedImage(frameWidth, frameHeight, BufferedImage.TYPE_INT_ARGB); bufferedImage.setRGB(0, 0, frameWidth, frameHeight, pixelInts, 0, frameWidth); try { javax.imageio.ImageIO.write(bufferedImage, "PNG", new File(filename)); } catch (IOException e) { System.out.println("Error: ImageIO.write."); e.printStackTrace(); } /* End code taken from: http://www.felixgers.de/teaching/jogl/imagingProg.html */ /* final BufferedImage image = new BufferedImage( this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics gr = image.getGraphics(); this.printAll(gr); gr.dispose(); try { ImageIO.write(image, "PNG", new File(filename)); } catch (IOException e) { System.out.println( "Error: ImageIO.write." ); e.printStackTrace(); } */ }
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; }
public static BufferedImage convertToARGB(BufferedImage image) { BufferedImage newImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = newImage.createGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); return newImage; }
public void drawScaledImage(BufferedImage im, int x, int y, int w, int h) { float scaleX = w * 1.0f / im.getWidth(); float scaleY = h * 1.0f / im.getHeight(); AffineTransform tx = new AffineTransform(); tx.scale(scaleX, scaleY); BufferedImageOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR); drawImage(im, op, x, y); }
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 static BufferedImage resize(BufferedImage image, int width, int height) { BufferedImage bi = new BufferedImage(width, height, BufferedImage.TRANSLUCENT); Graphics2D g2d = (Graphics2D) bi.createGraphics(); g2d.addRenderingHints( new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)); g2d.drawImage(image, 0, 0, width, height, null); g2d.dispose(); return bi; }
// initialize default image private BufferedImage getDefaultImage(int w, int h) { BufferedImage defaultImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = defaultImage.createGraphics(); graphics2D.setColor(new Color(200, 200, 200)); graphics2D.fillRect(0, 0, w, h); graphics2D.setColor(new Color(130, 130, 130)); graphics2D.drawRect(0, 0, w - 1, h - 1); return defaultImage; }
public JackPanel(JumpingJack jj, long period) { jackTop = jj; this.period = period; setDoubleBuffered(false); setBackground(Color.white); setPreferredSize(new Dimension(PWIDTH, PHEIGHT)); setFocusable(true); requestFocus(); // the JPanel now has focus, so receives key events addKeyListener( new KeyAdapter() { public void keyPressed(KeyEvent e) { processKey(e); } }); // initialise the loaders ImagesLoader imsLoader = new ImagesLoader(IMS_INFO); clipsLoader = new ClipsLoader(SNDS_FILE); // initialise the game entities bricksMan = new BricksManager(PWIDTH, PHEIGHT, BRICKS_INFO, imsLoader); int brickMoveSize = bricksMan.getMoveSize(); ribsMan = new RibbonsManager(PWIDTH, PHEIGHT, brickMoveSize, imsLoader); jack = new JumperSprite( PWIDTH, PHEIGHT, brickMoveSize, bricksMan, imsLoader, (int) (period / 1000000L)); // in ms fireball = new FireBallSprite(PWIDTH, PHEIGHT, imsLoader, this, jack); // prepare the explosion animation explosionPlayer = new ImagesPlayer("explosion", (int) (period / 1000000L), 0.5, false, imsLoader); BufferedImage explosionIm = imsLoader.getImage("explosion"); explWidth = explosionIm.getWidth(); explHeight = explosionIm.getHeight(); explosionPlayer.setWatcher(this); // report animation's end back here // prepare title/help screen helpIm = imsLoader.getImage("title"); showHelp = true; // show at start-up isPaused = true; // set up message font msgsFont = new Font("SansSerif", Font.BOLD, 24); metrics = this.getFontMetrics(msgsFont); } // end of JackPanel()
public void paint(Graphics g) { // image=tool.getImage(imageName); int h = image2.getHeight(this) / 2; int w = image2.getWidth(this) / 2; g.drawImage(image2, 150, 100, this); // g.drawImage(this.image2, 150+w+30, 100,w,h,this); // g.drawString(imageName, 170, 50); }
public static ImageIcon generateIcon(Color _color) { int size = (int) (16 * scaleFactor); BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setColor(Color.BLACK); graphics.fillRect(0, 0, size, size); graphics.setColor(_color); graphics.fillRect(1, 1, size - 2, size - 2); return new ImageIcon(image); }
public void drawTileNumC(int tileNum, int x, int y, Color c, Graphics g) { BufferedImage coloredTile = tiles[tileNum]; for (int i = 0; i < this.tW; i++) { for (int j = 0; j < this.tH; j++) { Color originalColor = new Color(coloredTile.getRGB(i, j), true); Color nc = new Color(c.getRed(), c.getGreen(), c.getBlue(), originalColor.getAlpha()); coloredTile.setRGB(i, j, nc.getRGB()); } } g.drawImage(tiles[tileNum], x, y, null); }
/** * @param pixels - Byte Array with Pixels * @param w - Image Width (columns) * @param h - Image Heigth (row) */ PanelImage(byte[] pixels, int w, int h, boolean quad) { if (quad) { bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); bi.setRGB(0, 0, w, h, byteArrayToIntArrayQuad(pixels), 0, w); } else { bi = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR); bi.setRGB(0, 0, w, h, byteArrayToIntArray(pixels, w, h), 0, w); } this.setPreferredSize(new Dimension(w, h)); this.setVisible(true); }
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); }
public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w, h); g2.drawImage(bi, -x, -y, null); // this); g2.dispose(); return image; }
public void paint(Graphics g) { synchronized (this) { Graphics2D g2d = (Graphics2D) g; if (img != null) { int imgw = img.getWidth(); int imgh = img.getHeight(); g2d.setComposite(AlphaComposite.Src); g2d.drawImage(img, null, 0, 0); } } }
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)); }
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); }