List of usage examples for java.awt Graphics drawImage
public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer);
From source file:gui.grafica.estadisticas.GUIPanelGrafica.java
@Override public void paint(java.awt.Graphics g) { //super.paint(g); if (buffer == null) { buffer = creaImagen();/*from w w w.jav a 2 s . co m*/ } float fancho = this.getAlignmentX(); float falto = this.getAlignmentY(); int alto = Math.round(falto); int ancho = Math.round(fancho); if (g == null) { // g = new Graphics(); } g.drawImage(buffer, alto, ancho, null); }
From source file:ClipImage.java
public void paint(Graphics g) { w = getWidth();// w w w.j a va 2s. c om h = getHeight(); if (w <= 0 || h <= 0) return; Graphics2D g2 = createDemoGraphics2D(g); drawDemo(g2); g2.dispose(); if (offImg != null && isShowing()) { g.drawImage(offImg, 0, 0, this); } newBufferedImage = false; }
From source file:org.gcaldaemon.core.notifier.GmailNotifierWindow.java
public final void paint(Graphics g) { if (offscreen != null) { synchronized (RENDER_LOCK) { g.drawImage(buffer, 0, 0, null); }/*from w ww . ja v a2 s. c o m*/ } }
From source file:ScaleTest_2008.java
/** * Progressive Bilinear approach: this method gets each scaled version from * the getOptimalScalingImage method and copies it into place. *///from ww w . j av a 2 s . c o m private void drawBetterImage(Graphics g, int yLoc) { int xLoc = 100; int delta = (int) (SCALE_FACTOR * FULL_SIZE); for (int scaledSize = FULL_SIZE; scaledSize > 0; scaledSize -= delta) { Image scaledImage = getOptimalScalingImage(originalImage, FULL_SIZE, scaledSize); g.drawImage(scaledImage, xLoc, yLoc + (FULL_SIZE - scaledSize) / 2, null); xLoc += scaledSize + 20; } }
From source file:MainClass.java
public void paint(Graphics gg) { int h = 150;//from www . j a v a 2 s .c om int w = 150; int pixels[] = new int[w * h]; int i = 0; int r = 0, g = 0, b = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < h; x++) { r = (x ^ y) & 0xff; g = (x * 2 ^ y * 2) & 0xff; b = (x * 4 ^ y * 4) & 0xff; pixels[i++] = (255 << 24) | (r << 16) | (g << 8) | b; } } Image art = createImage(new MemoryImageSource(w, h, pixels, 0, w)); gg.drawImage(art, 0, 0, this); }
From source file:Hypnosis.java
/** * Swing calls this method to ask the component to redraw itself. This * method uses double-buffering to make the animation smoother. Swing does * double-buffering automatically, so this may not actually make much * difference, but it is important to understand the technique. */// www.j a va2 s . c o m public void paintComponent(Graphics g) { // Clear the background of the off-screen image osg.setColor(getBackground()); osg.fillRect(0, 0, buffer.getWidth(), buffer.getHeight()); // Now draw a black spiral into the off-screen image osg.setColor(Color.black); osg.draw(new Spiral(r2 + linewidth / 2, r2 + linewidth / 2, r1, a1, r2, a2)); // Now copy that off-screen image onto the screen g.drawImage(buffer, (int) (x - r2), (int) (y - r2), this); }
From source file:TrackFocusDemo.java
protected void paintComponent(Graphics graphics) { Graphics g = graphics.create(); //Draw in our entire space, even if isOpaque is false. g.setColor(Color.WHITE);//from ww w . ja va 2 s. c o m g.fillRect(0, 0, image == null ? 125 : image.getWidth(this), image == null ? 125 : image.getHeight(this)); if (image != null) { //Draw image at its natural size of 125x125. g.drawImage(image, 0, 0, this); } //Add a border, red if picture currently has focus if (isFocusOwner()) { g.setColor(Color.RED); } else { g.setColor(Color.BLACK); } g.drawRect(0, 0, image == null ? 125 : image.getWidth(this), image == null ? 125 : image.getHeight(this)); g.dispose(); }
From source file:J3dSwingFrame.java
/** * Set the texture on our goemetry/* w ww .j a v a 2 s . com*/ * <P> * Always specified as a URL so that we may fetch it from anywhere. * * @param url * The url to the image. */ public void setTexture(URL url) { Toolkit tk = Toolkit.getDefaultToolkit(); Image src_img = tk.createImage(url); BufferedImage buf_img = null; if (!(src_img instanceof BufferedImage)) { // create a component anonymous inner class to give us the image // observer we need to get the width and height of the source image. Component obs = new Component() { }; int width = src_img.getWidth(obs); int height = src_img.getHeight(obs); // construct the buffered image from the source data. buf_img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics g = buf_img.getGraphics(); g.drawImage(src_img, 0, 0, null); g.dispose(); } else buf_img = (BufferedImage) src_img; src_img.flush(); ImageComponent img_comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, buf_img); texture = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, img_comp.getWidth(), img_comp.getHeight()); appearance.setTexture(texture); buf_img.flush(); }
From source file:examples.gp.monalisa.gui.EvolutionRunnable.java
public void run() { Configuration.reset();//from w w w .j a va 2 s. co m try { final DrawingGPConfiguration conf = new DrawingGPConfiguration(m_view.getTargetImage()); JFreeChart chart = m_view.getChart(); XYSeriesCollection sc = (XYSeriesCollection) chart.getXYPlot().getDataset(); XYSeries series = sc.getSeries(0); series.clear(); IEventManager eventManager = conf.getEventManager(); eventManager.addEventListener(GeneticEvent.GPGENOTYPE_EVOLVED_EVENT, new GeneticEventListener() { /** * Updates the chart in the main view. * * @param a_firedEvent the event */ public void geneticEventFired(GeneticEvent a_firedEvent) { GPGenotype genotype = (GPGenotype) a_firedEvent.getSource(); int evno = genotype.getGPConfiguration().getGenerationNr(); if (evno % 25 == 0) { double bestFitness = genotype.getFittestProgram().getFitnessValue(); JFreeChart chart = m_view.getChart(); XYSeriesCollection sc = (XYSeriesCollection) chart.getXYPlot().getDataset(); XYSeries series = sc.getSeries(0); series.add(evno, bestFitness); } } }); eventManager.addEventListener(GeneticEvent.GPGENOTYPE_NEW_BEST_SOLUTION, new GeneticEventListener() { private transient Logger LOGGER2 = Logger.getLogger(EvolutionRunnable.class); private DrawingGPProgramRunner gpProgramRunner = new DrawingGPProgramRunner(conf); /** * Display best solution in fittestChromosomeView's mainPanel. * * @param a_firedEvent the event */ public void geneticEventFired(GeneticEvent a_firedEvent) { GPGenotype genotype = (GPGenotype) a_firedEvent.getSource(); IGPProgram best = genotype.getAllTimeBest(); ApplicationData data = (ApplicationData) best.getApplicationData(); LOGGER2.info("Num Points / Polygons: " + data.numPoints + " / " + data.numPolygons); BufferedImage image = gpProgramRunner.run(best); Graphics g = m_view.getFittestDrawingView().getMainPanel().getGraphics(); if (!initView) { m_view.getFittestDrawingView().setSize(204, 200 + 30); m_view.getFittestDrawingView().getMainPanel().setSize(200, 200); initView = true; } g.drawImage(image, 0, 0, m_view.getFittestDrawingView()); if (m_view.isSaveToFile()) { int fitness = (int) best.getFitnessValue(); String filename = "monalisa_" + NumberKit.niceNumber(fitness, 5, '_') + ".png"; java.io.File f = new java.io.File(filename); try { javax.imageio.ImageIO.write(image, "png", f); } catch (java.io.IOException iex) { iex.printStackTrace(); } } } }); GPProblem problem = new DrawingProblem(conf); GPGenotype gp = problem.create(); gp.setVerboseOutput(true); while (m_view.isEvolutionActivated()) { gp.evolve(); gp.calcFitness(); if (gp.getGPConfiguration().getGenerationNr() % 25 == 0) { String freeMB = SystemKit.niceMemory(SystemKit.getFreeMemoryMB()); LOGGER.info("Evolving gen. " + (gp.getGPConfiguration().getGenerationNr()) + ", mem free: " + freeMB + " MB"); } } // Create graphical tree from currently fittest image. // --------------------------------------------------- IGPProgram best = gp.getAllTimeBest(); int fitness = (int) best.getFitnessValue(); String filename = "monalisa_" + NumberKit.niceNumber(fitness, 5, '_') + ".png"; problem.showTree(best, filename); } catch (InvalidConfigurationException e) { e.printStackTrace(); System.exit(-1); } }
From source file:algorithm.ImageImageFrameExpanding.java
/** * This method appends the payload image to the bottom of the carrier image. * Furthermore restoration information is added. * //w w w . j a v a 2 s . com * @param carrier * The file where the payload should be added * @param payload * @throws IOException */ private void append(File carrier, File payload) throws IOException { BufferedImage carrierImage = ImageIO.read(carrier); BufferedImage payloadImage = ImageIO.read(payload); if (carrierImage == null || payloadImage == null) { return;// "This wan't an image! Return." } BufferedImage outputImage = getOutputImage(carrierImage, payloadImage); BufferedImage metadataImage = getMetadataImage(carrier, payload); Graphics graphics = outputImage.getGraphics(); graphics.drawImage(carrierImage, 0, 0, null); graphics.drawImage(payloadImage, 0, carrierImage.getHeight(), null); graphics.drawImage(metadataImage, 0, carrierImage.getHeight() + payloadImage.getHeight(), null); writeImage(carrier, outputImage); }