當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageWriter.addIIOWriteProgressListener方法代碼示例

本文整理匯總了Java中javax.imageio.ImageWriter.addIIOWriteProgressListener方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageWriter.addIIOWriteProgressListener方法的具體用法?Java ImageWriter.addIIOWriteProgressListener怎麽用?Java ImageWriter.addIIOWriteProgressListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.imageio.ImageWriter的用法示例。


在下文中一共展示了ImageWriter.addIIOWriteProgressListener方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doTest

import javax.imageio.ImageWriter; //導入方法依賴的package包/類
public void doTest() {
    try {
        System.out.println("Progress test for " + compression_type);
        BufferedImage bi = new BufferedImage(20, 300, BufferedImage.TYPE_INT_RGB);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageOutputStream ios = ImageIO.createImageOutputStream(baos);

        Iterator iter = ImageIO.getImageWritersByFormatName(format);
        if (!iter.hasNext()) {
            throw new RuntimeException("No available writer for " + format);
        }
        ImageWriter writer = (ImageWriter)iter.next();

        writer.setOutput(ios);
        writer.addIIOWriteProgressListener(listener);

        IIOImage iio_img = new IIOImage(bi, null, null);

        ImageWriteParam param = writer.getDefaultWriteParam();

        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionType(compression_type);


        writer.write(null, iio_img, param);

        if (!listener.isTestPassed) {
            throw new RuntimeException("Test for " + compression_type + " does not finish correctly!");
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:WriteProgressListenerTest.java

示例2: test

import javax.imageio.ImageWriter; //導入方法依賴的package包/類
private void test(final ImageWriter writer) throws IOException {
    // Image initialization
    final BufferedImage imageWrite = new BufferedImage(WIDTH, HEIGHT,
                                                       TYPE_BYTE_BINARY);
    final Graphics2D g = imageWrite.createGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, WIDTH, HEIGHT);
    g.dispose();

    // File initialization
    final File file = File.createTempFile("temp", ".img");
    file.deleteOnExit();
    final FileOutputStream fos = new SkipWriteOnAbortOutputStream(file);
    final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
    writer.setOutput(ios);
    writer.addIIOWriteProgressListener(this);

    // This write will be aborted, and file will not be touched
    writer.write(imageWrite);
    if (!isStartedCalled) {
        throw new RuntimeException("Started should be called");
    }
    if (!isProgressCalled) {
        throw new RuntimeException("Progress should be called");
    }
    if (!isAbortCalled) {
        throw new RuntimeException("Abort should be called");
    }
    if (isCompleteCalled) {
        throw new RuntimeException("Complete should not be called");
    }
    // Flush aborted data
    ios.flush();

    // This write should be completed successfully and the file should
    // contain correct image data.
    abortFlag = false;
    isAbortCalled = false;
    isCompleteCalled = false;
    isProgressCalled = false;
    isStartedCalled = false;
    writer.write(imageWrite);

    if (!isStartedCalled) {
        throw new RuntimeException("Started should be called");
    }
    if (!isProgressCalled) {
        throw new RuntimeException("Progress should be called");
    }
    if (isAbortCalled) {
        throw new RuntimeException("Abort should not be called");
    }
    if (!isCompleteCalled) {
        throw new RuntimeException("Complete should be called");
    }
    writer.dispose();
    ios.close();

    // Validates content of the file.
    final BufferedImage imageRead = ImageIO.read(file);
    for (int x = 0; x < WIDTH; ++x) {
        for (int y = 0; y < HEIGHT; ++y) {
            if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) {
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:69,代碼來源:WriteAfterAbort.java

示例3: WriteAbortTest

import javax.imageio.ImageWriter; //導入方法依賴的package包/類
public WriteAbortTest(String format) throws Exception {
    try {
        System.out.println("Test for format " + format);
        bimg = new BufferedImage(width, heght,
                BufferedImage.TYPE_INT_RGB);

        Graphics2D g = bimg.createGraphics();
        g.setColor(srccolor);
        g.fillRect(0, 0, width, heght);
        g.dispose();

        file = File.createTempFile("src_", "." + format, new File("."));
        ImageInputStream ios = ImageIO.createImageOutputStream(file);

        ImageWriter writer =
                ImageIO.getImageWritersByFormatName(format).next();

        writer.setOutput(ios);
        writer.addIIOWriteProgressListener(this);

        // Abort writing in IIOWriteProgressListener.imageStarted().
        startAbort = true;
        writer.write(bimg);
        startAbort = false;

        // Abort writing in IIOWriteProgressListener.imageProgress().
        progressAbort = true;
        writer.write(bimg);
        progressAbort = false;

        ios.close();
        /*
         * All abort requests from imageStarted,imageProgress
         * from IIOWriteProgressListener should be reached
         * otherwise throw RuntimeException.
         */
        if (!(startAborted
                && progressAborted)) {
            throw new RuntimeException("All IIOWriteProgressListener abort"
                    + " requests are not processed for format "
                    + format);
        }
    } finally {
        Files.delete(file.toPath());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:47,代碼來源:WriteAbortTest.java

示例4: doTest

import javax.imageio.ImageWriter; //導入方法依賴的package包/類
public static void doTest(boolean writeSequence) throws IOException {
    String format = "GIF";
    ImageWriter writer =
            ImageIO.getImageWritersByFormatName(format).next();
    if (writer == null) {
        throw new RuntimeException("No writer available for " + format);
    }

    BufferedImage img = createTestImage();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    writer.setOutput(ios);

    WriterReuseTest t = new WriterReuseTest();
    writer.addIIOWriteProgressListener(t);

    ImageWriteParam param = writer.getDefaultWriteParam();
    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(param);
    IIOImage iioImg = new IIOImage(img, null, null);
    if (writeSequence) {
        writer.prepareWriteSequence(streamMetadata);
        writer.writeToSequence(iioImg, param);
    } else {
        writer.write(img);
    }

    if (!t.isWritingAborted || t.isWritingCompleted) {
        throw new RuntimeException("Test failed.");
    }
    t.reset();

    // next attempt after abort
    ImageOutputStream ios2 =
         ImageIO.createImageOutputStream(new ByteArrayOutputStream());
    writer.setOutput(ios2);
    if (writeSequence) {
        writer.writeToSequence(iioImg, param);
    } else {
        writer.write(img);
    }

    if (t.isWritingAborted || !t.isWritingCompleted) {
        throw new RuntimeException("Test failed.");
    }
    System.out.println("Test passed.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:47,代碼來源:WriterReuseTest.java

示例5: test

import javax.imageio.ImageWriter; //導入方法依賴的package包/類
private void test(final ImageWriter writer) throws IOException {
    try {
        // Image initialization
        final BufferedImage imageWrite =
                new BufferedImage(WIDTH, HEIGHT, TYPE_BYTE_BINARY);
        final Graphics2D g = imageWrite.createGraphics();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, WIDTH, HEIGHT);
        g.dispose();

        // File initialization
        file = File.createTempFile("temp", ".img");
        fos = new SkipWriteOnAbortOutputStream(file);
        final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
        writer.setOutput(ios);
        writer.addIIOWriteProgressListener(this);

        // This write will be aborted, and file will not be touched
        writer.write(imageWrite);
        if (!isStartedCalled) {
            throw new RuntimeException("Started should be called");
        }
        if (!isProgressCalled) {
            throw new RuntimeException("Progress should be called");
        }
        if (!isAbortCalled) {
            throw new RuntimeException("Abort should be called");
        }
        if (isCompleteCalled) {
            throw new RuntimeException("Complete should not be called");
        }
        // Flush aborted data
        ios.flush();

        /*
         * This write should be completed successfully and the file should
         * contain correct image data.
         */
        abortFlag = false;
        isAbortCalled = false;
        isCompleteCalled = false;
        isProgressCalled = false;
        isStartedCalled = false;
        writer.write(imageWrite);

        if (!isStartedCalled) {
            throw new RuntimeException("Started should be called");
        }
        if (!isProgressCalled) {
            throw new RuntimeException("Progress should be called");
        }
        if (isAbortCalled) {
            throw new RuntimeException("Abort should not be called");
        }
        if (!isCompleteCalled) {
            throw new RuntimeException("Complete should be called");
        }
        ios.close();

        // Validates content of the file.
        final BufferedImage imageRead = ImageIO.read(file);
        for (int x = 0; x < WIDTH; ++x) {
            for (int y = 0; y < HEIGHT; ++y) {
                if (imageRead.getRGB(x, y) != imageWrite.getRGB(x, y)) {
                    throw new RuntimeException("Test failed.");
                }
            }
        }
    } finally {
        writer.dispose();
        if (file != null) {
            if (fos != null) {
                fos.close();
            }
            Files.delete(file.toPath());
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:79,代碼來源:WriteAfterAbort.java


注:本文中的javax.imageio.ImageWriter.addIIOWriteProgressListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。