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));
}
}
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);
}
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);
}
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;
}
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;
}
Aggregations