Example usage for java.awt Graphics drawImage

List of usage examples for java.awt Graphics drawImage

Introduction

In this page you can find the example usage for java.awt Graphics drawImage.

Prototype

public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer);

Source Link

Document

Draws as much of the specified image as is currently available.

Usage

From source file:com.krawler.esp.handlers.FileUploadHandler.java

private BufferedImage toBufferedImage(Image image, int type) {
    image = new ImageIcon(image).getImage();
    BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
    Graphics g = bufferedImage.createGraphics();
    if (type == BufferedImage.TYPE_INT_RGB) {
        g.setColor(Color.white);/*www. ja  va2  s  . c  om*/
        g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
    }
    g.drawImage(image, 0, 0, null);
    g.dispose();

    return bufferedImage;
}

From source file:DoubleBufferedImage.java

public void paint(Graphics g) {
    if (xLocation == imageWidth)
        xLocation = 0;/*from   www. ja v  a  2s .co  m*/

    dbImageGraphics.clearRect(0, 0, imageWidth, imageHeight);
    dbImageGraphics.drawImage(originalImage, 0, 0, this);
    dbImageGraphics.setColor(Color.red);
    dbImageGraphics.fillOval(xLocation, imageHeight / 2, 20, 20);

    //now dbImage's drawing area appears
    g.drawImage(dbImage, 0, 0, this);

    xLocation++;
    repaint(10);
}

From source file:org.stanwood.nwn2.gui.view.UIFrameView.java

private void drawFramePart(Graphics g, int iconWidth, int iconHeight, int iconX, int iconY, String iconName)
        throws ImageException {
    if (iconName != null) {
        try {/*from  w  w w  .j a  v  a2s  .c om*/
            Image fill = getIconManager().getIcon(iconName).getScaledInstance(iconWidth, iconHeight,
                    Image.SCALE_SMOOTH);
            g.drawImage(fill, iconX, iconY, null);
        } catch (FileNotFoundException e) {
            log.error(e.getMessage());
        }
    }
}

From source file:SmoothMove.java

public void paint(Graphics g) {
    // Clear the offscreen image.
    Dimension d = getSize();//from  ww  w  . j  ava  2s.  c om
    checkOffscreenImage();
    Graphics offG = mImage.getGraphics();
    offG.setColor(getBackground());
    offG.fillRect(0, 0, d.width, d.height);
    // Draw into the offscreen image.
    paintOffscreen(mImage.getGraphics());
    // Put the offscreen image on the screen.
    g.drawImage(mImage, 0, 0, null);
}

From source file:ImageFrame.java

/**
 * Paint the image./*from  ww w.  ja  v  a  2 s.co m*/
 */
public void paint(Graphics g) {
    // the first time through, figure out where to draw the image
    if (left == -1) {
        Insets insets = getInsets();
        left = insets.left;
        top = insets.top;

        setSize(image.getWidth(null) + left + insets.right, image.getHeight(null) + top + insets.bottom);
    }
    g.drawImage(image, left, top, this);
}

From source file:test.uk.co.modularaudio.util.audio.controlinterpolation.InterpolatorVisualiser.java

@Override
public void paint(final Graphics g) {
    g.setColor(Color.WHITE);/*  ww  w  . ja va 2 s  .c o m*/
    g.fillRect(0, 0, SwingControlInterpolatorAnalyser.VIS_WIDTH + 1,
            SwingControlInterpolatorAnalyser.VIS_HEIGHT + 1);
    if (controlSrcVisualiser != null) {
        controlSrcVisualiser.paint(g);
    }
    g.drawImage(bi, 0, 0, null);
}

From source file:org.openstreetmap.gui.jmapviewer.Tile.java

/**
 * Paints the tile-image on the {@link Graphics} <code>g</code> at the
 * position <code>x</code>/<code>y</code>.
 * /*w w w  . ja v a  2  s .  c o m*/
 * @param g
 * @param x
 *            x-coordinate in <code>g</code>
 * @param y
 *            y-coordinate in <code>g</code>
 */
public void paint(Graphics g, int x, int y) {
    if (image == null) {
        return;
    }
    g.drawImage(image, x, y, null);
}

From source file:uk.co.modularaudio.mads.base.soundfile_player.ui.SoundfilePlayerWaveDisplayUiJComponent.java

@Override
public void paint(final Graphics g) {
    //      log.trace("WaveDisplay paint() called");
    if (rollPainter != null) {
        if (rollPainter.buffer0Visible()) {
            g.drawImage(rollPainter.buffer0.bi, rollPainter.buffer0XOffset, 0, null);
        }// w w  w  .  j a v  a 2 s.c om
        if (rollPainter.buffer1Visible()) {
            g.drawImage(rollPainter.buffer1.bi, rollPainter.buffer1XOffset, 0, null);
        }
    } else {
        g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_BACKGROUND_COLOR);
        g.fillRect(0, 0, displayWidth, displayHeight);
    }
    g.setColor(SoundfilePlayerColorDefines.WAVE_DISPLAY_CURRENT_POSITION_COLOUR);
    g.drawLine(displayWidthMinusOneOverTwo, 0, displayWidthMinusOneOverTwo, displayHeight);
}

From source file:ClipImage.java

public void paint(Graphics g) {
    w = getWidth();/*  w  w  w .ja va  2 s  .co  m*/
    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:com.actionbazaar.controller.SellController.java

/**
 * Saves the uploaded file into a folder for the user.
 * @param imageFile - image file to be saved
 * @return image id/*w  w  w  .j a  va  2  s . c o m*/
 */
private String save(UploadedFile imageFile) {
    try {
        File saveFld = new File(imageFolder + File.separator + userDisplay.getUser().getUsername());
        if (!saveFld.exists()) {
            if (!saveFld.mkdir()) {
                logger.log(Level.INFO, "Unable to create folder: {0}", saveFld.getAbsolutePath());
                return null;
            }
        }
        File tmp = File.createTempFile("img", "img");
        IOUtils.copy(imageFile.getInputstream(), new FileOutputStream(tmp));
        File thumbnailImage = new File(saveFld + File.separator + UUID.randomUUID().toString() + ".png");
        File fullResolution = new File(saveFld + File.separator + UUID.randomUUID().toString() + ".png");

        // Create the thumbnail
        BufferedImage image = ImageIO.read(tmp);
        Image thumbnailIm = image.getScaledInstance(310, 210, Image.SCALE_SMOOTH);
        // Convert the thumbnail java.awt.Image into a rendered image which we can save
        BufferedImage thumbnailBi = new BufferedImage(thumbnailIm.getWidth(null), thumbnailIm.getHeight(null),
                BufferedImage.TYPE_INT_RGB);
        Graphics bg = thumbnailBi.getGraphics();
        bg.drawImage(thumbnailIm, 0, 0, null);
        bg.dispose();

        ImageIO.write(thumbnailBi, "png", thumbnailImage);
        // Write out the full resolution image as a thumbnail
        ImageIO.write(image, "png", fullResolution);
        if (!tmp.delete()) {
            logger.log(Level.INFO, "Unable to delete: {0}", tmp.getAbsolutePath());
        }
        String imageId = UUID.randomUUID().toString();
        imageBean.addImage(imageId, new ImageRecord(imageFile.getFileName(), fullResolution.getAbsolutePath(),
                thumbnailImage.getAbsolutePath(), userDisplay.getUser().getUsername()));
        return imageId;
    } catch (Throwable t) {
        logger.log(Level.SEVERE, "Unable to save the image.", t);
        return null;
    }
}