FAQ Database Discussion Community


Why is my gif image sent from servlet not animating?

java,image,gif,bufferedimage,javax.imageio
I have this following code in my servlet response.setContentType("image/gif"); String filepath = "PATH//TO//GIF.gif"; OutputStream out = response.getOutputStream(); File f = new File(filepath); BufferedImage bi = ImageIO.read(f); ImageIO.write(bi, "gif", out); out.close(); This code is just returning first frame of the image. How to achieve returning full GIF image ?...

Images cannot be found in .jar file [duplicate]

java,jar,embedded-resource,javax.imageio,illegalargumentexception
This question already has an answer here: java.lang.IllegalArgumentException: input == null! when using ImageIO.read to load image as bufferedImage 6 answers This question is edited to include everything asked. New picture links will be added below. My program runs fine in NetBeans, and cannot load the program when running...

Powermock imageio UnsatisfiedLinkError

java,powermock,easymock,javax.imageio
After adding powermock (1.5.6 in combination with Easymock 3.2) to my current project (jdk 1.6.0) I get some test failures in test methods which worked perfectly fine before: java.lang.UnsatisfiedLinkError: com.sun.imageio.plugins.jpeg.JPEGImageReader.initReaderIDs(Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)V The following code fails: BufferedImage img = null; try { img = ImageIO.read(this.getClass().getResourceAsStream("/example.jpg")); } catch (IOException e) { fail(e.getMessage()); }...

Java IIOException caused by ZipException while trying to convert from String to PNG

java,servlets,png,bufferedimage,javax.imageio
My Java Servlet has a String coming from a client (all I know is that he is actually sending me a PNG as a parameter in a request with contentType = application/x-www-form-urlencoded), and I'm trying to convert it back to a File and save it. Here is my code (based...

Java's drawImage method doesn't show the image

java,javax.imageio,drawimage
I'm just beginner at Java Programming and am using NetBeans. The code below runs and No Error is displayed but no image is seen! This image is in the "frame" package beside this two classes. package frame; import javax.swing.JPanel; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; public class Screen...

How can I fetch image format from a URL in Java?

java,image,image-processing,bufferedimage,javax.imageio
I have an image that I fetch from a url that has no extension(jpg, gif,png, etc). I have no problem downloading the image. BufferedImage image = null; URL url = new URL(link); image = ImageIO.read(url); However, I wanted to know the extension of the file before saving to disk. I...

BufferedImage to InputStream - Format is different

java,inputstream,bufferedimage,javax.imageio
I am trying to convert my BufferedImage to an Inputstream using the following: BufferedImage bi = ImageIO.read(file.getInputStream()); bi = Scalr.resize(bi, 300); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageIO.write(bi, file.getContentType(), os); //the content type is specified as image/jpeg The problem I am facing is that my file.getContentType() returns the value as "image/jpeg"...

assign RGB values in java with nested for function

java,colors,rgb,pixels,javax.imageio
I have some question, here is my code : int W = img.getWidth(); int H = img.getHeight(); int [][] pixels = new int [W][H]; int [][][] rgb = new int [3][H][W]; for(int i=0;i<W;i++) for(int j=0;j<H;j++){ pixels[i][j] = img.getRGB(i,j); Color clr = new Color(pixels[i][j]); rgb[0][j][i] = clr.getRed(); rgb[1][j][i] = clr.getGreen(); rgb[2][j][i]...

Trying to set image icon for JLabel but URL returns null

java,image,swing,embedded-resource,javax.imageio
Trying to set image icon for JLabel but returns a null URL? I am using Netbeans and have included background.png in my project but it still returns null? import java.awt.image.BufferedImage; import java.net.URL; import javax.imageio.ImageIO; import javax.swing.*; public class NewClass extends JFrame { JLabel o = new JLabel(); public NewClass() {...

how to read an image from a url and convert it from CMYK to RGB in java?

java,javax.imageio,cmyk
I'm trying to read an image from a specific URL and convert it from CMYK to RGB. I saved the image into a file manually and used the code from 'How to convert from CMYK to RGB in Java correctly?' to do this. It works correctly but what if I...

Java - loading file for ImageIO.write doesn't work in .jar

java,eclipse,file,javax.imageio
I'm making a game in Java and I want to save the randomly generated map on an image and then load it. My code work without a problem in Eclipse, but when I export it to a .jar/.exe file it has problem with making a file ("mapf"). Thank you for...

How to have ImageIO.write create a folder path as needed

java,file,filepath,javax.imageio
I have the following code: String nameAndPath = "C:\\example\\folder\\filename.png"; BufferedImage image = addInfoToScreenshot(); //this method works fine and returns a BufferedImage ImageIO.write(image, "png", new File(nameAndPath)); Now, the path C:\example\folder\ does NOT exist, so I get an exception thrown with message: (The system cannot find the path specified) How can I...

multiple instances of a class, loading images, make more efficient in java

java,bufferedimage,javax.imageio
I am making a game that has 100 bees chase you and they have sprites. When they hit you, you lose a life. If you get hit by all 100, you die and the game resets. The problem is that when it resets, it reloads the images for each bee....