Search in sources :

Example 76 with BufferedImage

use of java.awt.image.BufferedImage in project darkFunction-Editor by darkFunction.

the class SpriteImageController method addSpriteButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
private void addSpriteButtonActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_addSpriteButtonActionPerformed
    File[] selectedFiles = this.showSetImageChooser();
    if (selectedFiles != null) {
        CustomNode parentNode = (CustomNode) nameTree.getSelectedNodeDir();
        if (parentNode == null)
            parentNode = _lastSelectedDirNode;
        if (parentNode == null)
            parentNode = (CustomNode) nameTree.getModel().getRoot();
        ArrayList<GraphicObject> graphicList = new ArrayList();
        for (int i = 0; i < selectedFiles.length; ++i) {
            try {
                BufferedImage bufferedImage = ImageIO.read(selectedFiles[i]);
                SpriteGraphic graphic = new SpriteGraphic(bufferedImage, new java.awt.Point(0, 0), new Rectangle(0, 0, bufferedImage.getWidth(), bufferedImage.getHeight()));
                graphicList.add(graphic);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(this, "Could not import " + selectedFiles[i].getName(), "Image not added", JOptionPane.ERROR_MESSAGE);
            }
        }
        cmdManager.execute(new AddGraphicListToSheetCommand(nameTree, parentNode, viewPanel, graphicList));
    }
}
Also used : ArrayList(java.util.ArrayList) Rectangle(java.awt.Rectangle) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage) File(java.io.File)

Example 77 with BufferedImage

use of java.awt.image.BufferedImage in project deeplearning4j by deeplearning4j.

the class DrawReconstruction method readjustToData.

public void readjustToData() {
    this.width = data.columns();
    this.height = data.rows();
    img = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
}
Also used : BufferedImage(java.awt.image.BufferedImage)

Example 78 with BufferedImage

use of java.awt.image.BufferedImage in project jmonkeyengine by jMonkeyEngine.

the class MipMapGenerator method resizeToPowerOf2.

public static void resizeToPowerOf2(Image image) {
    BufferedImage original = ImageToAwt.convert(image, false, true, 0);
    int potWidth = FastMath.nearestPowerOfTwo(image.getWidth());
    int potHeight = FastMath.nearestPowerOfTwo(image.getHeight());
    int potSize = Math.max(potWidth, potHeight);
    BufferedImage scaled = scaleDown(original, potSize, potSize);
    AWTLoader loader = new AWTLoader();
    Image output = loader.load(scaled, false);
    image.setWidth(potSize);
    image.setHeight(potSize);
    image.setDepth(0);
    image.setData(output.getData(0));
    image.setFormat(output.getFormat());
    image.setMipMapSizes(null);
}
Also used : AWTLoader(com.jme3.texture.plugins.AWTLoader) BufferedImage(java.awt.image.BufferedImage) Image(com.jme3.texture.Image) BufferedImage(java.awt.image.BufferedImage)

Example 79 with BufferedImage

use of java.awt.image.BufferedImage in project jmonkeyengine by jMonkeyEngine.

the class LwjglWindow method imagesToGLFWImages.

/**
     * Convert array of images to array of {@link GLFWImage}.
     */
private GLFWImage[] imagesToGLFWImages(final Object[] images) {
    final GLFWImage[] out = new GLFWImage[images.length];
    for (int i = 0; i < images.length; i++) {
        final BufferedImage image = (BufferedImage) images[i];
        out[i] = imageToGLFWImage(image);
    }
    return out;
}
Also used : GLFWImage(org.lwjgl.glfw.GLFWImage) GLFW.glfwWindowHint(org.lwjgl.glfw.GLFW.glfwWindowHint) BufferedImage(java.awt.image.BufferedImage)

Example 80 with BufferedImage

use of java.awt.image.BufferedImage in project jmonkeyengine by jMonkeyEngine.

the class LwjglWindow method imageToGLFWImage.

/**
     * Convert the {@link BufferedImage} to the {@link GLFWImage}.
     */
private GLFWImage imageToGLFWImage(BufferedImage image) {
    if (image.getType() != BufferedImage.TYPE_INT_ARGB_PRE) {
        final BufferedImage convertedImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
        final Graphics2D graphics = convertedImage.createGraphics();
        final int targetWidth = image.getWidth();
        final int targetHeight = image.getHeight();
        graphics.drawImage(image, 0, 0, targetWidth, targetHeight, null);
        graphics.dispose();
        image = convertedImage;
    }
    final ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);
    for (int i = 0; i < image.getHeight(); i++) {
        for (int j = 0; j < image.getWidth(); j++) {
            int colorSpace = image.getRGB(j, i);
            buffer.put((byte) ((colorSpace << 8) >> 24));
            buffer.put((byte) ((colorSpace << 16) >> 24));
            buffer.put((byte) ((colorSpace << 24) >> 24));
            buffer.put((byte) (colorSpace >> 24));
        }
    }
    buffer.flip();
    final GLFWImage result = GLFWImage.create();
    result.set(image.getWidth(), image.getHeight(), buffer);
    return result;
}
Also used : GLFWImage(org.lwjgl.glfw.GLFWImage) ByteBuffer(java.nio.ByteBuffer) BufferedImage(java.awt.image.BufferedImage) GLFW.glfwWindowHint(org.lwjgl.glfw.GLFW.glfwWindowHint) Graphics2D(java.awt.Graphics2D)

Aggregations

BufferedImage (java.awt.image.BufferedImage)1702 Graphics2D (java.awt.Graphics2D)376 IOException (java.io.IOException)220 File (java.io.File)195 FunctionException (lucee.runtime.exp.FunctionException)122 Graphics (java.awt.Graphics)104 ByteArrayOutputStream (java.io.ByteArrayOutputStream)89 Color (java.awt.Color)88 ByteArrayInputStream (java.io.ByteArrayInputStream)86 Test (org.junit.Test)81 WritableRaster (java.awt.image.WritableRaster)75 Point (java.awt.Point)71 Rectangle (java.awt.Rectangle)68 AffineTransform (java.awt.geom.AffineTransform)57 Image (java.awt.Image)56 InputStream (java.io.InputStream)51 Dimension (java.awt.Dimension)50 ImageIcon (javax.swing.ImageIcon)50 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)46 ImageWriter (javax.imageio.ImageWriter)45