bufferedimage

Program freezes during Thread.sleep() and with Timer

随声附和 提交于 2019-11-26 11:56:24
Original question: This method is supposed to change the image being displayed on a JFrame gradually into another image. However, without some way to slow it down, it just seems to change from one image to the new image. In order to slow it down, I put in a Thread.sleep(1000) so the changes wouldn't happen instantly. However, with this line in there, my program freezes completely. No error message, no nothing. Can anyone please help me out? Suggest a better method to slow it down, or how this can be fixed. For clarification: int k is the number of gradual steps in the change. k = 1 would be an

How do you clone a BufferedImage

非 Y 不嫁゛ 提交于 2019-11-26 11:46:27
I have an object which has many bufferedimages in it, I want to create a new object copying all the bufferedimages into the new object, but these new images may be altered and i don't want the original object images to be altered by altering the new objects images. is that clear? Is this possible to do and can anyone suggest a good way to do it please? I have thought of getSubImage but read somewhere that any changes to the subimage are relected back to the parent image. I just want to be able to get a fresh entirely separate copy or clone of a BufferedImage Something like this? static

Load a sprites image in java

丶灬走出姿态 提交于 2019-11-26 11:37:00
问题 I want to ask if why am getting error loading any sprite images into the object here is how I get the image in. import java.awt.image.BufferedImage; import java.io.IOException; public class SpriteSheet { public BufferedImage sprite; public BufferedImage[] sprites; int width; int height; int rows; int columns; public SpriteSheet(int width, int height, int rows, int columns, BufferedImage ss) throws IOException { this.width = width; this.height = height; this.rows = rows; this.columns = columns

How do I draw an image to a JPanel or JFrame?

断了今生、忘了曾经 提交于 2019-11-26 11:25:48
问题 How do I draw an Image to a JPanel or JFrame, I have already read oracle\'s tutorial on this but I can\'t seem to get it right. I need the image \" BeachRoad.png \" to be displayed on a specific set of coordinates. Here is what I have so far. public class Level1 extends JFrame implements ActionListener { static JLayeredPane EverythingButPlayer; static Level1 l1; public Level1() { EverythingButPlayer = new JLayeredPane(); BufferedImage img = null; try { img = ImageIO.read(new File(\"BeachRoad

Java: Filling a BufferedImage with transparent pixels

女生的网名这么多〃 提交于 2019-11-26 11:09:49
问题 I have an off-screen BufferedImage, constructed with the type BufferedImage.TYPE_INT_ARGB . It can contain anything, and I\'m looking for a way to (fairly efficiently) completely overwrite the image with transparent pixels, resulting in an \'invisible\' image. Using something like this: (bufimg.getGraphics()).setColor(new Color(10, 10, 100, 0)); (bufimg.getGraphics()).fillRect (0, 0, x, y); Has no effect. One possible method might be just to write over every pixel in the BufferedImage, but I\

Java: BufferedImage to byte array and back

好久不见. 提交于 2019-11-26 09:01:57
问题 I see that a number of people have had a similar problem, however I\'m yet to try find exactly what I\'m looking for. So, I have a method which reads an input image and converts it to a byte array: File imgPath = new File(ImageName); BufferedImage bufferedImage = ImageIO.read(imgPath); WritableRaster raster = bufferedImage .getRaster(); DataBufferByte data = (DataBufferByte) raster.getDataBuffer(); What I now want to do is convert it back into a BufferedImage (I have an application for which

java.lang.IllegalArgumentException: input == null! when using ImageIO.read to load image as bufferedImage

荒凉一梦 提交于 2019-11-26 08:35:04
问题 This is a question that has been asked like 100 times on this site, but I have looked at all of them and even though they all were solved, none of the solutions worked for me. Here\'s what my code looks like: public Button1(Client client, String imgName) { this.client = client; try { this.icon = ImageIO.read(this.getClass().getResourceAsStream(\"/resources/\" + imgName)); } catch (IOException e) { e.printStackTrace(); } When the code runs it results in the following error: Exception in thread

How to load BufferedImage in android?

为君一笑 提交于 2019-11-26 07:48:43
问题 I want to load BufferedImage in my application. For that I am using ImageIO but I am getting java.lang.NoClassDefFoundError : BufferedImage tgtImg = loadImage(\"ImageD2.jpg\"); public static BufferedImage loadImage(String ref) { BufferedImage bimg = null; try { bimg = ImageIO.read(new File(ref)); } catch (Exception e) { e.printStackTrace(); } return bimg; } but i am getting exception: 03-15 18:05:22.051: ERROR/AndroidRuntime(437): java.lang.NoClassDefFoundError: javax.imageio.ImageIO 回答1:

Drawing a Component to BufferedImage causes display corruption

妖精的绣舞 提交于 2019-11-26 06:49:30
问题 I am using the JScrollNavigator component described here, in order to provide a navigation window onto a large \"canvas-like\" CAD component I have embedded within a JScrollPane . I have tried to adapt the JScrollNavigator to draw a thumbnail image of the canvas to provide some additional context to the user. However, the action of doing this causes the rendering of my application\'s main frame to become corrupted. Specifically, it is the action of calling paint(Graphics) on the viewport

How to serialize an object that includes BufferedImages

余生长醉 提交于 2019-11-26 06:43:49
问题 I\'m trying to create a simple image editing program in java. I made an ImageCanvas object that has all the information about the image that is being edited (some basic properties, list of effects being applied, a list of BufferedImage layers, etc.) and I wanted a simple way to save it to disk so it could be opened again later. I figured that using Java\'s defualt Serializable interface might be exactly what I was looking for and I could just write the entire object to file and read it back