Java Code Examples for javax.imageio.ImageReadParam#setDestinationType()

The following examples show how to use javax.imageio.ImageReadParam#setDestinationType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageIOReader.java    From scrimage with Apache License 2.0 6 votes vote down vote up
private Optional<ImmutableImage> tryLoad(javax.imageio.ImageReader reader, ImageInputStream iis, Rectangle rectangle) {
   try {
      reader.setInput(iis);

      ImageReadParam params = reader.getDefaultReadParam();
      Iterator<ImageTypeSpecifier> imageTypes = reader.getImageTypes(0);
      if (imageTypes.hasNext()) {
         ImageTypeSpecifier imageTypeSpecifier = imageTypes.next();
         int bufferedImageType = imageTypeSpecifier.getBufferedImageType();
         params.setDestinationType(imageTypeSpecifier);
      }
      if (rectangle != null) {
         params.setSourceRegion(rectangle);
      }

      BufferedImage bufferedImage = reader.read(0, params);
      return Optional.of(ImmutableImage.wrapAwt(bufferedImage));
   } catch (IOException | InvalidImageParameterException e) {
      e.printStackTrace();
      return Optional.empty();
   }
}
 
Example 2
Source File: ReadAsGrayTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 3
Source File: ReadAsGrayTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 4
Source File: ReadAsGrayTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 5
Source File: ReadAsGrayTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 6
Source File: ReadAsGrayTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 7
Source File: ReadAsGrayTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 8
Source File: ReadAsGrayTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 9
Source File: ReadAsGrayTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 10
Source File: ReadAsGrayTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 11
Source File: ReadAsGrayTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 12
Source File: ReadAsGrayTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void testType(ImageReader reader,
                             ImageTypeSpecifier t,
                             BufferedImage src)
    throws IOException
{
    ImageReadParam p = reader.getDefaultReadParam();
    p.setDestinationType(t);
    BufferedImage dst = reader.read(0, p);

    verify(src, dst, t);
}
 
Example 13
Source File: PngOutputTypeTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 14
Source File: PngOutputTypeTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 15
Source File: PngOutputTypeTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 16
Source File: PngOutputTypeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 17
Source File: PngOutputTypeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 18
Source File: PngOutputTypeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 19
Source File: PngOutputTypeTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}
 
Example 20
Source File: PngOutputTypeTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public void doTest() throws IOException {
    /*
     * This test verifies that png images with color type RGB or RGBA
     * are decoded as buffered  image of some standard type.
     *
     * So we need to be sure that image provided by
     * user has required color type - RGB or RGBA
     */
    if (!checkImageType()) {
        System.out.println("Test IGNORED!");
        return;
    }

    def = reader.read(0);
    System.out.println("Default image type: " + def.getType());
    if (def == null || def.getType() == BufferedImage.TYPE_CUSTOM) {
        throw new RuntimeException("Test FAILED!");
    }

    raw_type = reader.getRawImageType(0);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setDestinationType(raw_type);

    System.out.println("Reading with raw image type...");
    raw = reader.read(0, param);
    System.out.println("Type of raw image is " + raw.getType());

    compare(def, raw);

    Iterator<ImageTypeSpecifier> types = reader.getImageTypes(0);
    while (types.hasNext()) {
        ImageTypeSpecifier t = types.next();
        System.out.println("Test type: " + t);
        param.setDestinationType(t);

        BufferedImage img = reader.read(0, param);
        System.out.println("Result type: " + img.getType());

        compare(def, img);
        System.out.println("Done.\n");
    }

    System.out.println("Test PASSED.");
}