本文整理汇总了Java中javax.imageio.ImageWriteParam.MODE_EXPLICIT属性的典型用法代码示例。如果您正苦于以下问题:Java ImageWriteParam.MODE_EXPLICIT属性的具体用法?Java ImageWriteParam.MODE_EXPLICIT怎么用?Java ImageWriteParam.MODE_EXPLICIT使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.imageio.ImageWriteParam
的用法示例。
在下文中一共展示了ImageWriteParam.MODE_EXPLICIT属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
RenderedImage img = image.getRenderedImage();
if (stream == null) {
throw new IOException("Set an output first!");
}
if (param == null) {
param = getDefaultWriteParam();
}
Rectangle sourceRegion = new Rectangle(0, 0, img.getWidth(), img.getHeight());
if (param.getSourceRegion() != null) {
sourceRegion = sourceRegion.intersection(param.getSourceRegion());
}
Raster raster = img.getData(sourceRegion);
int quality = 85;
if (param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
quality = (int) (param.getCompressionQuality() * 100);
}
try {
stream.write(lib.encode(raster, quality).array());
} catch (TurboJpegException e) {
throw new IOException(e);
}
}
示例2: TIFFDeflater
public TIFFDeflater(String compressionType,
int compressionTagValue,
ImageWriteParam param,
int predictorValue) {
super(compressionType, compressionTagValue, true);
this.predictor = predictorValue;
// Set the deflate level.
int deflateLevel;
if(param != null &&
param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
float quality = param.getCompressionQuality();
deflateLevel = (int)(1 + 8*quality);
} else {
deflateLevel = Deflater.DEFAULT_COMPRESSION;
}
this.deflater = new Deflater(deflateLevel);
}
示例3: main
public static void main(String args[]) throws Exception {
try {
int mode = ImageWriteParam.MODE_EXPLICIT;
String type = "BI_RLE4";
doTest(type, mode);
type = "BI_RLE8";
doTest(type, mode);
mode = ImageWriteParam.MODE_DEFAULT;
type = "BI_RLE4";
doTest(type, mode);
type = "BI_RLE8";
doTest(type, mode);
System.out.println("Test 4bpp image.");
encodeRLE4Test();
System.out.println("Test 8bpp image.");
encodeRLE8Test();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Unexpected exception. Test failed");
}
}
示例4: main
public static void main(String args[]) {
int[] iModes = { ImageWriteParam.MODE_DISABLED,
ImageWriteParam.MODE_EXPLICIT,
ImageWriteParam.MODE_COPY_FROM_METADATA,
ImageWriteParam.MODE_DEFAULT };
String[] strModes = { "ImageWriteParam.MODE_DISABLED",
"ImageWriteParam.MODE_EXPLICIT",
"ImageWriteParam.MODE_COPY_FROM_METADATA",
"ImageWriteParam.MODE_DEFAULT" };
for(int i=0; i<iModes.length; i++) {
System.out.println("Test compression mode "+strModes[i]);
doTest(iModes[i]);
}
}
示例5: getDefaultImageMetadata
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param) {
BMPMetadata meta = new BMPMetadata();
meta.bmpVersion = VERSION_3;
meta.compression = getPreferredCompressionType(imageType);
if (param != null
&& param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
meta.compression = BMPCompressionTypes.getType(param.getCompressionType());
}
meta.bitsPerPixel = (short)imageType.getColorModel().getPixelSize();
return meta;
}
示例6: getModeName
private static String getModeName(int mode) {
switch(mode) {
case ImageWriteParam.MODE_COPY_FROM_METADATA:
return "MODE_COPY_FROM_METADATA";
case ImageWriteParam.MODE_DEFAULT:
return "MODE_DEFAULT";
case ImageWriteParam.MODE_DISABLED:
return "MODE_DISABLED";
case ImageWriteParam.MODE_EXPLICIT:
return "MODE_EXPLICIT";
default:
throw new IllegalArgumentException("Unknown mode: " + mode);
}
}
示例7: doTest
private static void doTest(BufferedImage src,
String compressionType,
int compressionMode) throws IOException
{
ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix("bmp").next();
if (iw == null) {
throw new RuntimeException("No available writer. Test failed.");
}
IIOImage iioImg = new IIOImage(src, null, null);
ImageWriteParam param = iw.getDefaultWriteParam();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
iw.setOutput(ios);
System.out.println("Compression Type is " + compressionType);
System.out.println("Compression Mode is " + compressionMode);
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionType(compressionType);
if (compressionMode != ImageWriteParam.MODE_EXPLICIT) {
param.setCompressionMode(compressionMode);
}
try {
iw.write(null, iioImg, param);
} catch (IOException e) {
int bpp = src.getColorModel().getPixelSize();
if (compressionMode == ImageWriteParam.MODE_EXPLICIT) {
if ((compressionType.equals("BI_RLE4") && bpp != 4)
|| (compressionType.equals("BI_RLE8") && bpp != 8))
{
System.out.println("Can not encode "+ bpp+ "bpp image as"
+ compressionType);
return;
} else {
throw new RuntimeException("Unable to encode "
+ bpp + "bpp image as "
+ compressionType
+ ". Test failed");
}
}
}
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ImageInputStream iis = ImageIO.createImageInputStream(bais);
BufferedImage dst = ImageIO.read(iis);
int w = src.getWidth();
int h = src.getHeight();
Object dstPixel = dst.getRaster().getDataElements(w/2, h/2, null);
Object srcPixel = src.getRaster().getDataElements(w/2, h/2, null);
if ( (src.getColorModel().getRed(srcPixel)
!= dst.getColorModel().getRed(dstPixel))
|| (src.getColorModel().getGreen(srcPixel)
!= dst.getColorModel().getGreen(dstPixel))
|| (src.getColorModel().getBlue(srcPixel)
!= dst.getColorModel().getBlue(dstPixel))
|| (src.getColorModel().getAlpha(srcPixel)
!= dst.getColorModel().getAlpha(dstPixel)) ) {
showPixel(src, w/2, h/2);
showPixel(dst, w/2, h/2);
throw new RuntimeException(
"Colors are different: " +
Integer.toHexString(src.getColorModel().getRGB(srcPixel))
+ " and " +
Integer.toHexString(dst.getColorModel().getRGB(dstPixel)));
}
}
示例8: doTest
public void doTest() {
try {
System.out.println(this.getDescription());
if (param.getCompressionMode() != ImageWriteParam.MODE_EXPLICIT) {
System.out.println("Warning: compression mode is not MODE_EXPLICIT");
}
// change metadata according to ImageWriteParam
IIOMetadata new_meta = iw.convertImageMetadata(meta, new ImageTypeSpecifier(img), param);
IIOImage iio_img = new IIOImage(img, null, new_meta);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
iw.setOutput(ios);
System.out.print("write image...");
System.out.println("Current compression Type is \""+param.getCompressionType()+"\"");
iw.write(new_meta, iio_img, param);
//iw.write(iio_img);
System.out.println("OK");
System.out.print("read image ... ");
ios.flush();
byte[] ba_image = baos.toByteArray();
System.out.println("Array length=" + ba_image.length);
FileOutputStream fos = new FileOutputStream(new File(param.getCompressionType()+".bmp"));
fos.write(ba_image);
fos.flush();
fos = null;
ByteArrayInputStream bais = new ByteArrayInputStream(ba_image);
ImageReader ir = ImageIO.getImageReader(iw);
ir.setInput(ImageIO.createImageInputStream(bais));
BufferedImage res = ir.read(0);
System.out.println("OK");
if (!param.getCompressionType().equals("BI_JPEG")) {
System.out.print("compare images ... ");
boolean r = compare(img,res);
System.out.println(r?"OK":"FAILED");
if (!r) {
throw new RuntimeException("Compared images are not equals. Test failed.");
}
}
BMPMetadata mdata = (BMPMetadata)ir.getImageMetadata(0);
if (!param.getCompressionType().equals(param.getCompressionTypes()[mdata.compression])) {
throw new RuntimeException("Different compression value");
}
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException("Unexpected exception: " + ex);
}
}