本文整理匯總了Java中javax.imageio.ImageIO.getImageWriters方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageIO.getImageWriters方法的具體用法?Java ImageIO.getImageWriters怎麽用?Java ImageIO.getImageWriters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.imageio.ImageIO
的用法示例。
在下文中一共展示了ImageIO.getImageWriters方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import javax.imageio.ImageIO; //導入方法依賴的package包/類
public static void main(String[] args) {
for (int i = 0; i < types.length; i++) {
BufferedImage img = new BufferedImage(32, 32, types[i]);
ImageTypeSpecifier spec =
ImageTypeSpecifier.createFromRenderedImage(img);
Iterator writers = ImageIO.getImageWriters(spec, "png");
if (!writers.hasNext()) {
throw new RuntimeException("Test failed: " +
"no PNG writer found for type " +
typeNames[i]);
}
}
}
示例2: main
import javax.imageio.ImageIO; //導入方法依賴的package包/類
public static void main(String[] args) {
BufferedImage img = new BufferedImage(32, 32,
BufferedImage.TYPE_BYTE_INDEXED);
ImageTypeSpecifier spec =
ImageTypeSpecifier.createFromRenderedImage(img);
Iterator writers = ImageIO.getImageWriters(spec, "jpeg");
if (!writers.hasNext()) {
throw new RuntimeException("Test failed: " +
"no JPEG writer found for " +
"image with IndexColorModel");
}
}
示例3: testWriteRGB
import javax.imageio.ImageIO; //導入方法依賴的package包/類
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);
g.setColor(white);
g.fillRect(0, 0, width, height);
g.setColor(red);
g.fillRect(10, 10, 20, 20);
g.setColor(green);
g.fillRect(30, 30, 20, 20);
g.setColor(blue);
g.fillRect(50, 50, 20, 20);
ImageTypeSpecifier spec = new ImageTypeSpecifier(bi);
Iterator<ImageWriter> writers = ImageIO.getImageWriters(spec, format);
File file = new File("BitDepth_" + biTypeNames[type] + "." + format);
if (!writers.hasNext()) {
System.out.println("\tNo writers available for type " + biTypeNames[type]
+ " BufferedImage!");
} else {
ImageWriter writer = writers.next();
try (ImageOutputStream out = ImageIO.createImageOutputStream(file)) {
writer.setOutput(out);
writer.write(bi);
} catch (Exception e) {
System.out.println("\tCan't write a type " + biTypeNames[type]
+ " BufferedImage!");
return null;
}
}
return file;
}