bufferedimage

Java getSubimage() outside of raster

时光毁灭记忆、已成空白 提交于 2019-11-28 14:03:17
I'm trying to take an image and store it in an array of 16x16 subimages. The image I am using is 512x512 pixels. However, while iterating through the loop, getSubimage() is stopped by a Raster exception. Here is the code: public class TileList extends JPanel { private static final int width = 16; //width of a tile private static final int height = width; private int col = 1; private int row = 1; private BufferedImage image; File tilesetImage = new File("image.png"); BufferedImage tileset[]; public void loadAndSplitImage (File loadImage) { try{ image = ImageIO.read(loadImage); }catch(Exception

Removing transparency in PNG BufferedImage

二次信任 提交于 2019-11-28 13:55:30
I'm reading a PNG image with the following code: BufferedImage img = ImageIO.read(new URL(url)); Upon displaying it, there is a black background, which I know is caused from PNG transparency. I found solutions to this problem suggesting the use of BufferedImage.TYPE_INT_RGB , however I am unsure how to apply this to my code above. Create a second BufferedImage of type TYPE_INT_RGB ... BufferedImage copy = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB); Paint the original to the copy... Graphics2D g2d = copy.createGraphics(); g2d.setColor(Color.WHITE); // Or what

Trying to load image using ImageIO.read(class.getResource(URL)) but getResource is returning null

寵の児 提交于 2019-11-28 13:55:24
I've been making a 2D game with my buddy and I've been learning a lot about some basic game dev concepts through some Youtube tutorials. One of the things I was learning about is sprites (for those that don't know, 2D images to render to the screen) and how to use them in my game. I've been using ImageIO.read(this.class.getResource(pathToMySprite)) but it seems that getResource() is returning null for some reason. I've been screwing around with the path a little, adding "/" in front of it, removing "/", putting the user.dir property to see if it needed the whole path, and I'm still getting the

Why does ImageReader return incorrect BufferedImage?

亡梦爱人 提交于 2019-11-28 13:43:06
I'm trying to access a animated GIF image with 21 frames and then read the 12th (cause it starts at 0?) frame. import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.imageio.ImageIO; import javax.imageio.ImageReader; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.IOFileFilter; import org.apache.commons.io.filefilter.SuffixFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter; public class PictureSearch { public static void

.drawLine() issues and buffered image

半腔热情 提交于 2019-11-28 12:57:45
I have a paint programme and i have all the buttons and sliders done however i am having a problem with the actual painting itself. When I drag the cursor across the screen instead of an unbroken line I am getting almost a dotted line which i dont want. Here's the code for the MouseListener in the JPanel and BufferedImage : public void mouseDragged(MouseEvent e) { Graphics g=buffered.getGraphics(); g.setColor(mycol); Graphics2D graph=(Graphics2D)g; BasicStroke stroke=new BasicStroke(30); graph.setStroke(stroke); // g.fillRect(xcor, ycor, 20, 20); / /varx=e.getX(); ycor=e.getY(); xcor=e.getX();

Change the alpha value of a BufferedImage?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 12:17:34
How do I change the global alpha value of a BufferedImage in Java? (I.E. make every pixel in the image that has a alpha value of 100 have a alpha value of 80) I don't believe there's a single simple command to do this. A few options: copy into another image with an AlphaComposite specified (downside: not converted in place) directly manipulate the raster (downside: can lead to unmanaged images ) use a filter or BufferedImageOp The first is the simplest to implement, IMO. @Neil Coffey: Thanks, I've been looking for this too; however, Your code didn't work very well for me (white background

BufferedImage to BMP in Java

让人想犯罪 __ 提交于 2019-11-28 12:15:39
I have a BufferedImage object and I want to encode it to the BMP format and save it to disk. How do I do this? In JPEG it's ok: BufferedImage img; //here is an image ready to be recorded into the hard disk FileOutputStream fout = new FileOutputStream("image.jpg"); JPEGImageEncoder jencoder = JPEGCodec.createJPEGEncoder(fout); JPEGEncodeParam enParam = jencoder.getDefaultJPEGEncodeParam(img); enParam.setQuality(1.0F, true); jencoder.setJPEGEncodeParam(enParam); jencoder.encode(img); fout.close(); Marc Use ImageIO - ImageIO.write(img, "BMP", new File("filename.bmp")) Something like this should

Getting pixel RGB from a bufferedImage from the mouses X and Y position

末鹿安然 提交于 2019-11-28 11:51:36
I am making a color chooser program with an image. The program first loads in the image and then when you hover over the image, it will get the current pixels RGB value off of the mouses X and Y position. I have set up the frame and loaded them image, can someone help me get it working with the pixels? package net.ogpc.settings; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; import java.awt

Can I have image alpha fade from left to right in java?

感情迁移 提交于 2019-11-28 11:51:32
I am making a game and want to have a single image 'fade' from left to right with the left part of the image having an alpha of 1.0 and the right having an alpha of 0.0. (note: I do not want it to be changing what it looks like over time, like fading in or out, but just fading from left to right and staying constant). An attempt to draw what I want the end result to look like is below: lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l lll lll ll ll l l l l l Where the densities of the 'l's represent the alpha I am currently

Strange PNG errors: Bad length for IHDR chunk

浪子不回头ぞ 提交于 2019-11-28 11:46:41
Heres the error: Exception in thread "main" javax.imageio.IIOException: I/O error reading PNG header! at com.sun.imageio.plugins.png.PNGImageReader.readHeader(PNGImageReader.java:307) at com.sun.imageio.plugins.png.PNGImageReader.readMetadata(PNGImageReader.java:637) at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1212) at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1560) at javax.imageio.ImageIO.read(ImageIO.java:1422) at javax.imageio.ImageIO.read(ImageIO.java:1282) at Bundle.iconExists(Bundle.java:139) at Bundle.dPhIconExists(Bundle.java