Search in sources :

Example 71 with Graphics

use of java.awt.Graphics in project lwjgl by LWJGL.

the class TextureLoader method loadImage.

/**
     * Load a given resource as a buffered image
     *
     * @param ref The location of the resource to load
     * @return The loaded buffered image
     * @throws IOException Indicates a failure to find a resource
     */
private BufferedImage loadImage(String ref) throws IOException {
    URL url = TextureLoader.class.getClassLoader().getResource(ref);
    if (url == null) {
        throw new IOException("Cannot find: " + ref);
    }
    // due to an issue with ImageIO and mixed signed code
    // we are now using good oldfashioned ImageIcon to load
    // images and the paint it on top of a new BufferedImage
    Image img = new ImageIcon(url).getImage();
    BufferedImage bufferedImage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics g = bufferedImage.getGraphics();
    g.drawImage(img, 0, 0, null);
    g.dispose();
    return bufferedImage;
}
Also used : Graphics(java.awt.Graphics) ImageIcon(javax.swing.ImageIcon) IOException(java.io.IOException) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) URL(java.net.URL) BufferedImage(java.awt.image.BufferedImage)

Example 72 with Graphics

use of java.awt.Graphics in project Voxel_Game by ASasseCreations.

the class AssetLoader method loadModifiedTextures.

public static final void loadModifiedTextures() throws URISyntaxException, IOException {
    final List<String> list = getItems("/textures/blocks", "def");
    list.addAll(getItems(Content.MOD_TEXTURE_FOLDER, "def", true));
    for (final String s : list) {
        final String name = getName(s, 3);
        final BufferedImage original = RawAtlasTile.MODIFIED_IMAGE.get(name);
        final BufferedImage image = new BufferedImage(original.getWidth(), original.getHeight(), BufferedImage.TYPE_INT_ARGB);
        {
            final int[] pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();
            for (int i = 0; i < pixels.length; i++) pixels[i] = 0x00000000;
        }
        final Graphics g = image.getGraphics();
        try {
            final String[] def = Tools.getFileAsString(s).split(Tools.getNewLine());
            for (final String line : def) {
                final String[] lt = line.split(Tools.getWhiteSpace());
                if (lt[0].equals("fill")) {
                    g.setColor(new Color(Integer.parseInt(lt[1]), Integer.parseInt(lt[2]), Integer.parseInt(lt[3])));
                    g.fillRect(0, 0, image.getWidth(), image.getHeight());
                } else if (lt[0].equals("draw"))
                    g.drawImage(original, 0, 0, null);
            }
        } catch (final IOException | NullPointerException e) {
        }
        g.dispose();
        RawAtlasTile.MODIFIED_IMAGE.put(name, image);
    }
}
Also used : Graphics(java.awt.Graphics) Color(java.awt.Color) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Example 73 with Graphics

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

the class WelcomeScreen method initView.

/**
 * Creates all necessary components
 */
protected void initView() {
    mainPanel = new JPanel(new GridBagLayout()) {

        @Override
        public void paintComponent(Graphics g) {
            // paint gradient background
            Graphics2D g2 = (Graphics2D) g.create();
            Paint paint = new GradientPaint(0, 0, TOP_GRADIENT, 0, getHeight(), BOTTOM_GRADIENT);
            g2.setPaint(paint);
            g2.fillRect(0, 0, getWidth(), getHeight());
            g2.dispose();
        }
    };
    setBorder(BorderFactory.createEmptyBorder());
    initButtonsPane();
    initFileListPane();
    setViewportView(mainPanel);
}
Also used : Graphics(java.awt.Graphics) JPanel(javax.swing.JPanel) GridBagLayout(java.awt.GridBagLayout) GradientPaint(java.awt.GradientPaint) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) Graphics2D(java.awt.Graphics2D)

Example 74 with Graphics

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

the class Thumb method draw.

/**
 * 创建图层
 * @param img 源图
 * @param col 背景颜色
 * @param pos 停靠位置
 * @param w   目标宽
 * @param h   目标高
 * @param x   源图宽
 * @param y   源图高
 * @return    新的图层
 */
private BufferedImage draw(BufferedImage img, Color col, Position pos, int w, int h, int x, int y) {
    if (pos == Positions.TOP_LEFT) {
        x = 0;
        y = 0;
    } else if (pos == Positions.TOP_RIGHT) {
        x = (w - x);
        y = 0;
    } else if (pos == Positions.TOP_CENTER) {
        x = (w - x) / 2;
        y = 0;
    } else if (pos == Positions.BOTTOM_LEFT) {
        x = 0;
        y = (h - y);
    } else if (pos == Positions.BOTTOM_RIGHT) {
        x = (w - x);
        y = (h - y);
    } else if (pos == Positions.BOTTOM_CENTER) {
        x = (w - x) / 2;
        y = (h - y);
    } else if (pos == Positions.CENTER_LEFT) {
        x = 0;
        y = (h - y) / 2;
    } else if (pos == Positions.CENTER_RIGHT) {
        x = (w - x);
        y = (h - y) / 2;
    } else /* Default is CENTER CENTER */
    {
        x = (w - x) / 2;
        y = (h - y) / 2;
    }
    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, x, y, null);
    grp.dispose();
    return buf;
}
Also used : Graphics(java.awt.Graphics) BufferedImage(java.awt.image.BufferedImage)

Example 75 with Graphics

use of java.awt.Graphics in project sulky by huxi.

the class GraphicsUtilities method createCompatibleCopy.

public static BufferedImage createCompatibleCopy(BufferedImage image) {
    BufferedImage result = createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    Graphics g = result.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return result;
}
Also used : Graphics(java.awt.Graphics) 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