Java Code Examples for java.awt.image.BufferedImage#getPropertyNames()

The following examples show how to use java.awt.image.BufferedImage#getPropertyNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageManufacture.java    From MyBox with Apache License 2.0 6 votes vote down vote up
public static BufferedImage clone(BufferedImage source) {
    if (source == null) {
        return null;
    }
    try {
        ColorModel cm = source.getColorModel();
        Hashtable<String, Object> properties = null;
        String[] keys = source.getPropertyNames();
        if (keys != null) {
            properties = new Hashtable<>();
            for (String key : keys) {
                properties.put(key, source.getProperty(key));
            }
        }
        return new BufferedImage(cm, source.copyData(null), cm.isAlphaPremultiplied(), properties)
                .getSubimage(0, 0, source.getWidth(), source.getHeight());
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 2
Source File: GetPropertyNames.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 3
Source File: ImageDump.java    From commons-imaging with Apache License 2.0 5 votes vote down vote up
public void dumpBIProps(final String prefix, final BufferedImage src) {
    final String[] keys = src.getPropertyNames();
    if (keys == null) {
        LOGGER.fine(prefix + ": no props");
        return;
    }
    for (final String key : keys) {
        LOGGER.fine(prefix + ": " + key + ": "
                + src.getProperty(key));
    }
}
 
Example 4
Source File: GetPropertyNames.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 5
Source File: GetPropertyNames.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 6
Source File: GetPropertyNames.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 7
Source File: GetPropertyNames.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 8
Source File: GetPropertyNames.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 9
Source File: GetPropertyNames.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 10
Source File: GetPropertyNames.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 11
Source File: GetPropertyNames.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void validate(final BufferedImage bi, final int expected) {
    final String[] names = bi.getPropertyNames();
    if (names.length != expected) {
        throw new RuntimeException("Wrong number of names");
    }
    for (final String name : names) {
        final Object property = bi.getProperty(name);
        if (property == Image.UndefinedProperty || property == null) {
            throw new RuntimeException("Unexpected property");
        }
    }
}
 
Example 12
Source File: GetPropertyNames.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 13
Source File: GetPropertyNames.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 14
Source File: GetPropertyNames.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 15
Source File: GetPropertyNames.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 16
Source File: GetPropertyNames.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 17
Source File: GetPropertyNames.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 18
Source File: GetPropertyNames.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 19
Source File: GetPropertyNames.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}
 
Example 20
Source File: GetPropertyNames.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(final String[] args) {
    // default result is null
    if (defaultProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for null properties result is null
    final BufferedImage emptyProps = getBufferedImage(null);
    if (emptyProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for empty properties result is null
    final BufferedImage nullProps = getBufferedImage(new Properties());
    if (nullProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for non-string keys result is null
    final Properties properties = new Properties();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    final BufferedImage nonStringProps = getBufferedImage(properties);
    if (nonStringProps.getPropertyNames() != null) {
        throw new RuntimeException("PropertyNames should be null");
    }
    // for string keys result is not null
    properties.clear();
    properties.setProperty("1", "1");
    properties.setProperty("2", "2");
    validate(getBufferedImage(properties), 2);
    // for the mix of strings and objects result is not null
    properties.clear();
    properties.put(1, 1);
    properties.put(2, 2);
    properties.put(3, 3);
    properties.setProperty("key1", "value1");
    properties.setProperty("key2", "value2");
    final BufferedImage mixProps = getBufferedImage(properties);
    validate(mixProps, 2);
    if (!"value1".equals(mixProps.getProperty("key1"))
        || !"value2".equals(mixProps.getProperty("key2"))) {
        throw new RuntimeException("Wrong key-value pair");
    }
}