javax.imageio

ImageIO thread-safety

只愿长相守 提交于 2019-12-17 20:36:47
问题 I see in the javax.imageio spec that thread-safety is not a goal, despite I've seen several examples using ImageIO.read() and ImageIO.write() for uploading/sanitizing images in a web environment. So, my question is, despite what the spec says, is ImageIO thread-safe? 回答1: ImageIO is not thread safe (or at least one of it's plugins is not), in at least one of my environments. I am in the process of debugging an issue where png and jpg files don't get loaded correctly (sometimes solid gray,

Create Multi-Page Tiff with Java

佐手、 提交于 2019-12-17 19:59:10
问题 I'm interested in taking a tif image and adding a layer to it that contains text with Java, preferably with the Twelve Monkeys image library if possible. I can tweak the code from here to either add text to a tif or create a new tif of the same size with only text, but not save them as a multi-page tif. For example: import javax.imageio.*; import javax.imageio.stream.ImageOutputStream; import java.awt.*; import java.awt.image.*; import java.io.*; public class ImageUtil { public static void

Write dpi metadata to a jpeg image in Java

只愿长相守 提交于 2019-12-17 19:33:44
问题 I am trying to programatically set the dpi metadata of an jpeg image in Java. The source of the image is a scanner, so I get the horizontal/vertical resolution from TWAIN, along with the image raw data. I'd like to save this info for better print results. Here's the code I have so far. It saves the raw image (byteArray) to a JPEG file, but it ignores the X/Ydensity information I specify via IIOMetadata. Any advice what I'm doing wrong? Any other solution (third-party library, etc) would be

Convert Byte Array to image in Java - without knowing the type

主宰稳场 提交于 2019-12-17 16:34:00
问题 Sounds simple right? Use ImageIO.read(new ByteArrayInputStream(bytes)); Here's the wrinkle. For some reason it is detecting a jpeg as a bmp, and that is the first ImageReader returned when I call ImageInputStream iis = ImageIO.createImageInputStream(new ByteArrayInputStream(bytes)); Iterator<ImageReader> readers=ImageIO.getImageReaders(iis); This causes the image to come out corrupted. Is there a way to tell through java short of looking directly at the bytes for the header, and failing that

Including Images with an executable jar

别说谁变了你拦得住时间么 提交于 2019-12-17 05:13:14
问题 I have been browsing Stackoverflow all day looking for how to do this and I have not been successful yet I am packaging a quick game I made into a executable jar but I didnt reference the images correctly I just referenced the files background = ImageIO.read(new File("wood.jpeg")); I have my classes in src default package Im not sure where I should add the images or if I have to add it to the build path or correct way of adding the images to the build path in the newest version of eclipse 回答1

Convert each animated GIF frame to a separate BufferedImage

谁说我不能喝 提交于 2019-12-17 03:16:06
问题 I want to be able to take an animated GIF as input, count the frames (and perhaps other metadata), and convert each to a BufferedImage . How can I do this? 回答1: If you want all the frames to be the same size (for optimized GIFs) try something like this: try { String[] imageatt = new String[]{ "imageLeftPosition", "imageTopPosition", "imageWidth", "imageHeight" }; ImageReader reader = (ImageReader)ImageIO.getImageReadersByFormatName("gif").next(); ImageInputStream ciis = ImageIO

how to save the the image in folder on disk using java

风格不统一 提交于 2019-12-14 03:59:12
问题 I want to save the image on disk such as c:/images which is captured by webcam using java ..and again I want to display that image on JForm as a label... is this possible using java and netbeans I'm new in java 回答1: you can save image private static void save(String fileName, String ext) { File file = new File(fileName + "." + ext); BufferedImage image = toBufferedImage(file); try { ImageIO.write(image, ext, file); // ignore returned boolean } catch(IOException e) { System.out.println("Write

IllegalArgumentException Input == null

心已入冬 提交于 2019-12-14 03:12:00
问题 I am trying to read an Image as an InputStream . But for some reason I always get an IllegalArugmentException . Here is my code: BufferedImage i = null; i = ImageIO.read(getClass().getResourceAsStream("/res/graphics" + path)); 回答1: Reason: Your resource evaluates to null and that is why the exception API doc Throws: IllegalArgumentException - if input is null . Solution: If res/graphics/whatever is in classpath at root then it will return not null 回答2: Basically, the resource with the name

GIF image becomes wrong after ImageIO read() and write() operations

放肆的年华 提交于 2019-12-14 01:20:00
问题 I have this code. It simply reads a GIF file, redraws it with background and output to a new GIF file. The problem is the result file becomes strange. I have no idea why it becomes poor quality. The problem doesn't happen on JPG files. How to fix it? import java.awt.Color; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class ImageTest { public static void main

ImageIO Unsupported Image Type - TwelveMonkeys Plugin with fix not working?

北城余情 提交于 2019-12-13 20:09:10
问题 I encountered the Unsupported Image Type error due to an incompatible colour profile using com.sun.imageio.plugins.jpeg.JPEGImageReader . I later found the TwelveMonkeys plugins that are proven to fix this issue and have referenced the dependent .jars in my project classpath. I downloaded them from the TwelveMonkeys github repository. Note i'm using version 3.0.2 because I'm running on Java 6 with JDK 1.6.0_45. These are the .jars I've added to my project: common-lang-3.0.2.jar common-io-3.0