-
Bug
-
Resolution: Fixed
-
P3
-
7u45, 8, 9
-
b100
-
windows_7
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8149307 | 8u101 | Jayathirth D V | P3 | Resolved | Fixed | b01 |
JDK-8146972 | 8u92 | Jayathirth D V | P3 | Resolved | Fixed | b04 |
JDK-8155452 | emb-8u101 | Jayathirth D V | P3 | Resolved | Fixed | b01 |
FULL PRODUCT VERSION :
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
This bug:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4776576
seems to describe what's happening in 1.7.0_45 again.
To see the output:
http://stackoverflow.com/questions/20789043/image-changes-color-when-saved-with-java
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
public class ImageSaver {
public static void main(final String url) {
URL u = null;
try {
u = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
String file = url.substring(url.indexOf("//") + 2);
Path filePath = Paths.get("c:/").resolve(file);
try {
Files.createDirectories(filePath.getParent());
BufferedImage img = ImageIO.read(u);
ImageIO.write(img, "jpg", filePath.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
q&d:
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
public class ImageSaverWorkAround {
public static void main(final String url) {
URL u = null;
try {
u = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
String file = url.substring(url.indexOf("//") + 2);
Path filePath = Paths.get("c:/").resolve(file);
try {
Files.createDirectories(filePath.getParent());
Image img = Toolkit.getDefaultToolkit().createImage(url);
while (img.getWidth(null) == -1 || img.getHeight(null) == -1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
int w = img.getWidth(null);
int h = img.getHeight(null);
int type = BufferedImage.TYPE_INT_RGB;
BufferedImage pic = new BufferedImage(w, h, type);
Graphics2D g2 = pic.createGraphics();
g2.drawImage(img, 0, 0, null);
g2.dispose();
ImageIO.write(pic, "jpg", filePath.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
This bug:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4776576
seems to describe what's happening in 1.7.0_45 again.
To see the output:
http://stackoverflow.com/questions/20789043/image-changes-color-when-saved-with-java
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
public class ImageSaver {
public static void main(final String url) {
URL u = null;
try {
u = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
String file = url.substring(url.indexOf("//") + 2);
Path filePath = Paths.get("c:/").resolve(file);
try {
Files.createDirectories(filePath.getParent());
BufferedImage img = ImageIO.read(u);
ImageIO.write(img, "jpg", filePath.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
q&d:
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.imageio.ImageIO;
public class ImageSaverWorkAround {
public static void main(final String url) {
URL u = null;
try {
u = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
String file = url.substring(url.indexOf("//") + 2);
Path filePath = Paths.get("c:/").resolve(file);
try {
Files.createDirectories(filePath.getParent());
Image img = Toolkit.getDefaultToolkit().createImage(url);
while (img.getWidth(null) == -1 || img.getHeight(null) == -1) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
int w = img.getWidth(null);
int h = img.getHeight(null);
int type = BufferedImage.TYPE_INT_RGB;
BufferedImage pic = new BufferedImage(w, h, type);
Graphics2D g2 = pic.createGraphics();
g2.drawImage(img, 0, 0, null);
g2.dispose();
ImageIO.write(pic, "jpg", filePath.toFile());
} catch (IOException e) {
e.printStackTrace();
}
}
}
- backported by
-
JDK-8146972 ImageIO reader is not capable of reading JPEGs without JFIF header
-
- Resolved
-
-
JDK-8149307 ImageIO reader is not capable of reading JPEGs without JFIF header
-
- Resolved
-
-
JDK-8155452 ImageIO reader is not capable of reading JPEGs without JFIF header
-
- Resolved
-
- duplicates
-
JDK-6444933 ImageIO creates faulty images of certain standard JPG files
-
- Closed
-
-
JDK-8057666 Error in JPG Colorspace detection while reading using ImageIO
-
- Closed
-