本文整理汇总了Java中java.awt.image.BufferedImage.getPropertyNames方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.getPropertyNames方法的具体用法?Java BufferedImage.getPropertyNames怎么用?Java BufferedImage.getPropertyNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.image.BufferedImage
的用法示例。
在下文中一共展示了BufferedImage.getPropertyNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validate
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
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");
}
}
}
示例2: main
import java.awt.image.BufferedImage; //导入方法依赖的package包/类
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");
}
}