本文整理汇总了Java中javax.imageio.ImageWriteParam.setSourceSubsampling方法的典型用法代码示例。如果您正苦于以下问题:Java ImageWriteParam.setSourceSubsampling方法的具体用法?Java ImageWriteParam.setSourceSubsampling怎么用?Java ImageWriteParam.setSourceSubsampling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.ImageWriteParam
的用法示例。
在下文中一共展示了ImageWriteParam.setSourceSubsampling方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
private void write(File f, boolean subsample) throws IOException {
ImageOutputStream ios = ImageIO.createImageOutputStream(f);
writer.setOutput(ios);
ImageWriteParam p = writer.getDefaultWriteParam();
if (subsample) {
p.setSourceSubsampling(subSampleX, subSampleY, 0, 0);
}
writer.write(null, new IIOImage(img, null, null), p);
ios.close();
writer.reset();
}
示例2: BMPSubsamplingTest
import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
public BMPSubsamplingTest() throws IOException {
ImageWriter writer =
ImageIO.getImageWritersByFormatName(format).next();
ImageWriteParam wparam = writer.getDefaultWriteParam();
wparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
String[] types = wparam.getCompressionTypes();
for (int t = 0; t < img_types.length; t++) {
int img_type = img_types[t];
System.out.println("Test for " + getImageTypeName(img_type));
BufferedImage image = getTestImage(img_type);
ImageTypeSpecifier specifier = new ImageTypeSpecifier(image);
if (!writer.getOriginatingProvider().canEncodeImage(specifier)) {
System.out.println("Writer does not support encoding this buffered image type.");
continue;
}
for(int i=0; i<types.length; i++) {
if ("BI_JPEG".equals(types[i])) {
// exclude BI_JPEG from automatic test
// due to color diffusion effect on the borders.
continue;
}
if (canEncodeImage(types[i], specifier, img_type)) {
System.out.println("compression type: " + types[i] +
" Supported for " + getImageTypeName(img_type));
} else {
System.out.println("compression type: " + types[i] +
" NOT Supported for " + getImageTypeName(img_type));
continue;
}
ImageWriteParam imageWriteParam = getImageWriteParam(writer, types[i]);
imageWriteParam.setSourceSubsampling(srcXSubsampling,
srcYSubsampling,
0, 0);
File outputFile = new File("subsampling_test_" +
getImageTypeName(img_type) + "__" +
types[i] + ".bmp");
ImageOutputStream ios =
ImageIO.createImageOutputStream(outputFile);
writer.setOutput(ios);
IIOImage iioImg = new IIOImage(image, null, null);
writer.write(null, iioImg, imageWriteParam);
ios.flush();
ios.close();
BufferedImage outputImage = ImageIO.read(outputFile);
checkTestImage(outputImage);
}
}
}