当前位置: 首页>>代码示例>>Java>>正文


Java属性javax.imageio.ImageWriteParam.MODE_EXPLICIT代码示例

以下是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个开源代码实例,这些例子默认根据受欢迎程度排序。您可以为喜欢的代码打CALL点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: write

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
@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);
  }
}
 
开发者ID:dbmdz,项目:imageio-jnr,完整代码来源:TurboJpegImageWriter.java


示例2: TIFFDeflater

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目:openjdk-jdk10,完整代码来源:TIFFDeflater.java


示例3: main

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
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");
    }
}
 
开发者ID:AdoptOpenJDK,项目:openjdk-jdk10,完整代码来源:RleEncodingTest.java


示例4: main

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
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]);
    }
}
 
开发者ID:AdoptOpenJDK,项目:openjdk-jdk10,完整代码来源:CompressionModeTest.java


示例5: getDefaultImageMetadata

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
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;
}
 
开发者ID:SunburstApps,项目:OpenJSharp,完整代码来源:BMPImageWriter.java


示例6: getModeName

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:AdoptOpenJDK,项目:openjdk-jdk10,完整代码来源:DisableCompressionTest.java


示例7: doTest

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
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)));
    }

}
 
开发者ID:AdoptOpenJDK,项目:openjdk-jdk10,完整代码来源:RleEncodingTest.java


示例8: doTest

import javax.imageio.ImageWriteParam; //导入方法依赖的package包/类
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);
    }

}
 
开发者ID:AdoptOpenJDK,项目:openjdk-jdk10,完整代码来源:BMPCompressionTest.java



注:本文示例均筛选自Github等开源项目,代码版权请参考对应项目的License;未经允许,请勿转载。