javax.imageio

Java casting / classloader issues

自闭症网瘾萝莉.ら 提交于 2019-12-01 06:39:09
问题 Here is the simplified version of the problem: SomeClass c = (SomeClass) obj.getSomeClassParent() not always but it happens sometimes to trigger exception org.somepackage.SomeClass can't be cast to org.somepackage.SomeClass How is this possible ? I suppose it has something to do with the fact that JAI imageio is native lib, but relay how can this happen ? I'm probably missing something but what ? I'm using JAI imageio version 1.1 dcm4che 2.0.21 DICOM lib Here is the original code

How to resolve OutOfMemoryError with ImageIO plugins as the cause?

拥有回忆 提交于 2019-12-01 06:20:06
At work we have some tomcat servers running several webapps, about half of which have to do some image processing. Before doing their image processing, these webapps do a ImageIO.scanForPlugins() to get the appropriate image readers and writers into memory. While before this was just run anytime an image needed to be processed, we now run the scan only when the webapps are initialized (since we don't add any jars after running, why run the scan more than once?) Some days later, the tomcat instance crashed due to an OutOfMemoryError . Luckily we had the HeapDumpOnOutOfMemoryError option set, so

Storing DPI and Paper Size information in a JPEG with Java

一个人想着一个人 提交于 2019-12-01 06:19:23
问题 I have the following code: ImageIO.write(originalImage, OUTPUT_TYPE, resultOutput); This is an invocation of the following javax.imageio.ImageIO method: public static boolean write(RenderedImage im, String formatName, File output) throws IOException This turns an original BMP image into a JGP output. Is it possible to also store DPI and Paper Size information in the JPEG to aid in printing operations? 回答1: Luckily, the java image I/O API lets you do just that. It also allows for setting the

Reading images using ImageIO.read(file); causes java.lang.OutOfMemoryError: Java heap space

巧了我就是萌 提交于 2019-12-01 05:47:10
问题 I am using a ImageIO API to write a PNG file. This code is called in a loop and causes an OutOfMemory error. Is there anyway the following code can be fixed to avoid the OutOfMemory error? Or is the only option to increase the JVM heap size? File file = new File(resultMap.get("outputFile").toString()); //ImageIO to convert jpg to png BufferedImage img = ImageIO.read(file); file = new File(resultMap.get("outputFile").toString() + ".png"); ImageIO.write(img, "png", file); Java heap size is

How to resolve OutOfMemoryError with ImageIO plugins as the cause?

怎甘沉沦 提交于 2019-12-01 04:37:57
问题 At work we have some tomcat servers running several webapps, about half of which have to do some image processing. Before doing their image processing, these webapps do a ImageIO.scanForPlugins() to get the appropriate image readers and writers into memory. While before this was just run anytime an image needed to be processed, we now run the scan only when the webapps are initialized (since we don't add any jars after running, why run the scan more than once?) Some days later, the tomcat

Combining images where BG is a JPEG causes unexpected results

白昼怎懂夜的黑 提交于 2019-12-01 04:33:45
Why does combining images where BG is a JPEG cause unexpected results? This is a follow-up to my answer in Overlaying of 2 images doesnt work properly . The source posted there (using a BG image created in memory) looks like this: The BG image is on the left. The FG image (a PNG with transparency) is in the middle. The combined image is on the right. So far, so good. But then the person who asked the question commented that if the BG was a JPEG, it failed. Thinking they were mistaken, I altered my example to encode the BG image to a JPEG. Now if I use BufferedImage.TYPE_INT_ARGB or

Is javax.imageio.ImageIO broken? It imports some images as rotated

删除回忆录丶 提交于 2019-12-01 04:21:30
Below you will see a picture of beatiful pastry called " simit " from Turkey. It is taken from iPad 2, therefore it is a JPEG with dimensions 720*960 . The problem is, when I use javax.imageio.ImageIO.read method, the image it strangely imports is to a BufferedImage rotated to left and becomes 960*720 . I reproduced this in my Sun JVM 1.6.0_29 on OS X and Sun JVM 1.6.0_26 on Debian. Here's the code: public class Main { public static void main(String[] args) throws Exception { FileInputStream stream = new FileInputStream(new File("IMG_0159.JPG")); BufferedImage img = ImageIO.read(stream);

Is javax.imageio.ImageIO broken? It imports some images as rotated

南笙酒味 提交于 2019-12-01 01:12:13
问题 Below you will see a picture of beatiful pastry called "simit" from Turkey. It is taken from iPad 2, therefore it is a JPEG with dimensions 720*960 . The problem is, when I use javax.imageio.ImageIO.read method, the image it strangely imports is to a BufferedImage rotated to left and becomes 960*720 . I reproduced this in my Sun JVM 1.6.0_29 on OS X and Sun JVM 1.6.0_26 on Debian. Here's the code: public class Main { public static void main(String[] args) throws Exception { FileInputStream

Image changes color when saved with java [duplicate]

孤者浪人 提交于 2019-11-30 15:26:39
问题 This question already has answers here : JPEG image with wrong colors (8 answers) Closed 5 years ago . When I save this image: with this method: private final static Path ROOT_PATH = Paths.getPath("C:/images"); private static void saveImageFromWebSimple(final String url) { URL u = null; try { u = new URL(url); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } String file = url.substring(url.indexOf("//") + 2); Path filePath = ROOT_PATH.resolve(file)

Image changes color when saved with java [duplicate]

醉酒当歌 提交于 2019-11-30 14:18:24
This question already has an answer here: JPEG image with wrong colors 7 answers When I save this image: with this method: private final static Path ROOT_PATH = Paths.getPath("C:/images"); private static void saveImageFromWebSimple(final String url) { URL u = null; try { u = new URL(url); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } String file = url.substring(url.indexOf("//") + 2); Path filePath = ROOT_PATH.resolve(file); try { Files.createDirectories(filePath.getParent()); BufferedImage img = ImageIO.read(u); ImageIO.write(img, "jpg",