Search in sources :

Example 76 with Graphics

use of java.awt.Graphics in project HongsCORE by ihongs.

the class Thumb method draw.

/**
 * 创建图层
 * @param img 源图
 * @param col 背景颜色
 * @param w   目标宽
 * @param h   目标高
 * @return    新的图层
 */
private BufferedImage draw(BufferedImage img, Color col, int w, int h) {
    BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    Graphics grp = buf.createGraphics();
    if (col != null) {
        grp.setColor(col);
        grp.fillRect(0, 0, w, h);
    }
    grp.drawImage(img, 0, 0, null);
    grp.dispose();
    return buf;
}
Also used : Graphics(java.awt.Graphics) BufferedImage(java.awt.image.BufferedImage)

Example 77 with Graphics

use of java.awt.Graphics in project suite by stupidsing.

the class AnimationMain method run.

protected boolean run(String[] args) throws InterruptedException {
    JFrame frame = new JFrame("Animation");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setSize(new Dimension(1024, 768));
    frame.setVisible(true);
    PaintInput pi = new PaintInput();
    frame.getContentPane().add(new JPanel() {

        private static final long serialVersionUID = 1l;

        protected void paintComponent(Graphics graphics) {
            super.paintComponent(graphics);
            Graphics2D g2d = (Graphics2D) graphics;
            g2d.setColor(Color.BLACK);
            g2d.fillRect(pi.i, pi.i, 32, 32);
        }
    });
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(4);
    executor.scheduleAtFixedRate(() -> {
        pi.i++;
        frame.repaint();
    }, 10, 10, TimeUnit.MILLISECONDS);
    executor.awaitTermination(100, TimeUnit.SECONDS);
    return true;
}
Also used : Graphics(java.awt.Graphics) JPanel(javax.swing.JPanel) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) JFrame(javax.swing.JFrame) Dimension(java.awt.Dimension) Graphics2D(java.awt.Graphics2D)

Example 78 with Graphics

use of java.awt.Graphics in project cxf by apache.

the class SwAOutInterceptor method convertToBufferedImage.

private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    // Wait until the image is completely loaded
    MediaTracker tracker = new MediaTracker(new Component() {

        private static final long serialVersionUID = 6412221228374321325L;
    });
    tracker.addImage(image, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        throw new Fault(e);
    }
    // Create a BufferedImage so we can write it out later
    BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
    Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
}
Also used : Graphics(java.awt.Graphics) MediaTracker(java.awt.MediaTracker) Fault(org.apache.cxf.interceptor.Fault) Component(java.awt.Component) BufferedImage(java.awt.image.BufferedImage)

Example 79 with Graphics

use of java.awt.Graphics in project Java by bottleleung.

the class Bitmap method createScaledBitmap.

/**
 * ����ͼƬ
 * @param src
 * @param width
 * @param height
 * @param tf
 */
public static Bitmap createScaledBitmap(Bitmap src, int width, int height, boolean tf) {
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics g = img.getGraphics();
    g.drawImage(src.image, 0, 0, width, height, 0, 0, src.getWidth(), src.getHeight(), null);
    return new Bitmap(img);
}
Also used : Graphics(java.awt.Graphics) BufferedImage(java.awt.image.BufferedImage)

Example 80 with Graphics

use of java.awt.Graphics in project cxf by apache.

the class ImageHelper method convertToBufferedImage.

private static BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage) image;
    }
    /*not sure how this is used*/
    MediaTracker tracker = new MediaTracker(null);
    tracker.addImage(image, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        throw new IOException(e.getMessage());
    }
    BufferedImage bufImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
}
Also used : Graphics(java.awt.Graphics) MediaTracker(java.awt.MediaTracker) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

Graphics (java.awt.Graphics)217 BufferedImage (java.awt.image.BufferedImage)104 Dimension (java.awt.Dimension)35 Point (java.awt.Point)32 Graphics2D (java.awt.Graphics2D)31 Color (java.awt.Color)28 JPanel (javax.swing.JPanel)22 Insets (java.awt.Insets)21 Rectangle (java.awt.Rectangle)21 JLabel (javax.swing.JLabel)19 BorderLayout (java.awt.BorderLayout)18 File (java.io.File)18 FontMetrics (java.awt.FontMetrics)16 Frame (java.awt.Frame)16 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)16 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)16 Component (java.awt.Component)15 Font (java.awt.Font)15 GridBagLayout (java.awt.GridBagLayout)15 JScrollPane (javax.swing.JScrollPane)15