publicstaticvoid main(String[] args) throws IOException { new BitDepth(args);
}
// Check that the PNG writer can write an all-white image correctly privatestaticboolean testPNGByteBinary() throws IOException { int width = 10; int height = 10;
File f = new File("BlackStripe.png");
BufferedImage bi = new BufferedImage(width, height,
BufferedImage.TYPE_BYTE_BINARY);
Graphics2D g = bi.createGraphics();
g.setColor(new Color(255, 255, 255));
g.fillRect(0, 0, width, height);
for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int rgb = bi2.getRGB(x, y); if (rgb != 0xffffffff) {
System.out.println("Found a non-white pixel!"); returnfalse;
}
}
}
for (int type : biRGBTypes) { // TODO: remove the following 'if' block after the 8147448 fix if ( format.toLowerCase().equals("bmp") && (
(type == BufferedImage.TYPE_INT_ARGB ) ||
(type == BufferedImage.TYPE_INT_ARGB_PRE ) ||
(type == BufferedImage.TYPE_4BYTE_ABGR ) ||
(type == BufferedImage.TYPE_4BYTE_ABGR_PRE ))) {
System.err.println("cannot use " + biTypeNames[type] + " for bmp because of JDK-8147448.\t" + " please update the test after fix of this bug!"); continue;
}
System.out.println("Testing " + format + " writer for type " + biTypeNames[type]);
File f = testWriteRGB(format, type); if (f == null) continue;
boolean ok = testReadRGB(f); if (ok) {
f.delete();
}
allOK = allOK && ok;
}
if (format.equals("png")) {
System.out.println("Testing png writer for black stripe"); boolean ok = testPNGByteBinary();
allOK = allOK && ok;
}
if (!allOK) { thrownew RuntimeException("Test failed");
}
}
private File testWriteRGB(String format, int type) throws IOException {
BufferedImage bi = new BufferedImage(width, height, type);
Graphics2D g = bi.createGraphics();
Color white = new Color(255, 255, 255);
Color red = new Color(255, 0, 0);
Color green = new Color(0, 255, 0);
Color blue = new Color(0, 0, 255);
BufferedImage bi = ImageIO.read(file); if (bi == null) {
System.out.println("Couldn't read image!"); returnfalse;
} int r = bi.getRGB(15, 15); if (colorDistance(r, 255, 0, 0) > 20) {
System.out.println("Red was distorted!"); returnfalse;
} int g = bi.getRGB(35, 35); if (colorDistance(g, 0, 255, 0) > 20) {
System.out.println("Green was distorted!"); returnfalse;
} int b = bi.getRGB(55, 55); if (colorDistance(b, 0, 0, 255) > 20) {
System.out.println("Blue was distorted!"); returnfalse;
} int w = bi.getRGB(55, 15); if (colorDistance(w, 255, 255, 255) > 20) {
System.out.println("White was distorted!"); returnfalse;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.