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


Java ImageOutputStream.close方法代码示例

本文整理汇总了Java中javax.imageio.stream.ImageOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java ImageOutputStream.close方法的具体用法?Java ImageOutputStream.close怎么用?Java ImageOutputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.imageio.stream.ImageOutputStream的用法示例。


在下文中一共展示了ImageOutputStream.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeImageWithHist

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
protected File writeImageWithHist(BufferedImage bi) throws IOException {
    File f = File.createTempFile("hist_", ".png", new File("."));

    ImageWriter writer = ImageIO.getImageWritersByFormatName("PNG").next();

    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    writer.setOutput(ios);

    ImageWriteParam param = writer.getDefaultWriteParam();
    ImageTypeSpecifier type = new ImageTypeSpecifier(bi);

    IIOMetadata imgMetadata = writer.getDefaultImageMetadata(type, param);

    /* add hIST node to image metadata */
    imgMetadata = upgradeMetadata(imgMetadata, bi);

    IIOImage iio_img = new IIOImage(bi,
                                    null, // no thumbnails
                                    imgMetadata);

    writer.write(iio_img);
    ios.flush();
    ios.close();
    return f;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:ShortHistogramTest.java

示例2: createGif

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Create the gif and clear down afterwards.
 * 
 * @return the gif byte data
 * @throws IOException if the output fails
 */
public byte[] createGif() throws IOException {
	try {
		ImageOutputStream ios = ImageIO.createImageOutputStream(baos); // N.b. not try with closure because we need to close the stream before returning
		ImageWriter iw = ImageIO.getImageWritersByFormatName("gif").next();	
		iw.setOutput(ios);
		iw.prepareWriteSequence(null);
		int index = 0;
		ImageWriteParam iwp = iw.getDefaultWriteParam();
		String frameDelay = String.valueOf(OptionsObject.getInstance().getGifDisplayTimeMillis() / 10L);
		log.debug("Frames size: {}, Free memory {}", frames.size(), Runtime.getRuntime().freeMemory());
		for (BufferedImage frame : frames) {
			IIOMetadata metadata = iw.getDefaultImageMetadata(new ImageTypeSpecifier(frame), iwp);
			configureMetaData(metadata, frameDelay, index++);
			iw.writeToSequence(new IIOImage(frame, null, metadata), null);
		}
		iw.endWriteSequence();
		ios.close();
		return baos.toByteArray();
	} finally {
		baos = null;
		frames = null;
	}
}
 
开发者ID:KodeMunkie,项目名称:imagetozxspec,代码行数:30,代码来源:GifConverter.java

示例3: doModification

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
private BufferedImage doModification(BufferedImage src) {
    try {
        BufferedImage dst = null;
        if (!writer.getOriginatingProvider().canEncodeImage(src)) {
            throw new RuntimeException(writingFormat+" writer does not support the image type "+type);
        }
        System.out.println(writingFormat+" writer claims it can encode the image "+type);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
        writer.setOutput(ios);
        writer.write(src);
        ios.close();
        baos.close();

        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
        dst = ImageIO.read(bais);
        return dst;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:WritingColorChangeTest.java

示例4: encode

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
/**
 * Encodes an image in JPEG format and writes it to an output stream.
 *
 * @param bufferedImage  the image to be encoded (<code>null</code> not 
 *     permitted).
 * @param outputStream  the OutputStream to write the encoded image to 
 *     (<code>null</code> not permitted).
 * 
 * @throws IOException if there is an I/O problem.
 * @throws NullPointerException if <code>bufferedImage</code> is 
 *     <code>null</code>.
 */
public void encode(BufferedImage bufferedImage, OutputStream outputStream) 
        throws IOException {
    if (bufferedImage == null) {
        throw new IllegalArgumentException("Null 'image' argument.");
    }
    if (outputStream == null) {
        throw new IllegalArgumentException("Null 'outputStream' argument.");
    }
    Iterator iterator = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = (ImageWriter) iterator.next();
    ImageWriteParam p = writer.getDefaultWriteParam();
    p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    p.setCompressionQuality(this.quality);
    ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream);
    writer.setOutput(ios);
    writer.write(null, new IIOImage(bufferedImage, null, null), p);
    ios.flush();
    writer.dispose();
    ios.close();
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:33,代码来源:SunJPEGEncoderAdapter.java

示例5: createAnimatedImage

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
public void createAnimatedImage(BufferedImage bi, IIOMetadata metadata,
        ImageWriter writer, File outputFile) {
    try {

        fos = new FileOutputStream(outputFile);
        ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
        System.out.println(ios);
        writer.setOutput(ios);

        ImageWriteParam param = writer.getDefaultWriteParam();
        IIOMetadata streamData = writer.getDefaultStreamMetadata(param);

        writer.prepareWriteSequence(streamData);
        ImageTypeSpecifier specify = new ImageTypeSpecifier(bi);
        IIOMetadata imgData = writer.convertImageMetadata(
                (IIOMetadata) metadata, specify, param);
        GIFImageMetadata gifData = setAnimationProperties(imgData);
        IIOImage iim = new IIOImage(bi, null, gifData);
        param.setProgressiveMode(param.MODE_DISABLED);
        writer.writeToSequence(iim, param);
        writer.endWriteSequence();
        ios.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:OpaquePNGToGIFTest.java

示例6: runTest

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    final Context ictx = (Context)ctx;
    final ImageWriter writer = ictx.writer;
    final BufferedImage image = ictx.image;
    do {
        try {
            ImageOutputStream ios = ictx.createImageOutputStream();
            writer.setOutput(ios);
            writer.write(image);
            writer.reset();
            ios.close();
            ictx.closeOriginalStream();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } while (--numReps >= 0);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:OutputImageTests.java

示例7: writeTest

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
public byte[] writeTest(BufferedImage bi,
                        ImageWriteParam p,
                        IIOMetadata m) throws IOException {
    ByteArrayOutputStream baos =
        new ByteArrayOutputStream();

    // write test image as jpeg
    ImageOutputStream ios =
        ImageIO.createImageOutputStream(baos);
    w.setOutput(ios);
    w.write(null,
            new IIOImage(bi, null, m),
            p);
    ios.close();
    return baos.toByteArray();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:DestTypeTest.java

示例8: main

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    Iterator witer = ImageIO.getImageWritersByFormatName("png");
    ImageWriter w = (ImageWriter)witer.next();

    File f = File.createTempFile("WriteProgressive", ".png");
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    w.setOutput(ios);

    BufferedImage bi = new BufferedImage(100, 100,
                                         BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = bi.createGraphics();
    Random r = new Random(10);
    for (int i = 0; i < 10000; i++) {
        Color c =
            new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
        g.setColor(c);
        g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1);
    }

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

    ImageWriteParam param = w.getDefaultWriteParam();
    param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);

    try {
        w.write(null, iioimage, param);
    } catch (NullPointerException npe) {
        throw new RuntimeException("Got NPE during write!");
    }

    ios.close();

    BufferedImage bi2 = ImageIO.read(f);
    f.delete();

    ImageCompare.compare(bi, bi2);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:WriteProgressive.java

示例9: createTestImage

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
private static Image createTestImage() throws IOException  {
    BufferedImage frame1 = createFrame(new int[] { 0xffff0000, 0xffff0000 });
    BufferedImage frame2 = createFrame(new int[] { 0xff0000ff, 0xffff0000 });

    ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(new File("lut_test.gif"));
    ImageWriteParam param = writer.getDefaultWriteParam();
    writer.setOutput(ios);
    writer.prepareWriteSequence(null);
    writer.writeToSequence(new IIOImage(frame1, null, null), param);
    writer.writeToSequence(new IIOImage(frame2, null, null), param);
    writer.endWriteSequence();
    writer.reset();
    writer.dispose();

    ios.flush();
    ios.close();

    return Toolkit.getDefaultToolkit().createImage("lut_test.gif");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:LUTCompareTest.java

示例10: main

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {

        OutputStream outputStream = new NullOutputStream();
        ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(outputStream);
        try {
            ImageIO.write(createImage(2048),"PNG", imageOutputStream);
        } catch (IOException e) {
            imageOutputStream.close();
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:PngForceStopWritingTest.java

示例11: print

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
public Base64Data print(Image v) {
    ByteArrayOutputStreamEx imageData = new ByteArrayOutputStreamEx();
    XMLSerializer xs = XMLSerializer.getInstance();

    String mimeType = xs.getXMIMEContentType();
    if(mimeType==null || mimeType.startsWith("image/*"))
        // because PNG is lossless, it's a good default
        //
        // mime type can be a range, in which case we can't just pass that
        // to ImageIO.getImageWritersByMIMEType, so here I'm just assuming
        // the default of PNG. Not sure if this is complete.
        mimeType = "image/png";

    try {
        Iterator<ImageWriter> itr = ImageIO.getImageWritersByMIMEType(mimeType);
        if(itr.hasNext()) {
            ImageWriter w = itr.next();
            ImageOutputStream os = ImageIO.createImageOutputStream(imageData);
            w.setOutput(os);
            w.write(convertToBufferedImage(v));
            os.close();
            w.dispose();
        } else {
            // no encoder
            xs.handleEvent(new ValidationEventImpl(
                ValidationEvent.ERROR,
                Messages.NO_IMAGE_WRITER.format(mimeType),
                xs.getCurrentLocation(null) ));
            // TODO: proper error reporting
            throw new RuntimeException("no encoder for MIME type "+mimeType);
        }
    } catch (IOException e) {
        xs.handleError(e);
        // TODO: proper error reporting
        throw new RuntimeException(e);
    }
    Base64Data bd = new Base64Data();
    imageData.set(bd,mimeType);
    return bd;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:41,代码来源:RuntimeBuiltinLeafInfoImpl.java

示例12: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:EncodeSubImageTest.java

示例13: writeWithCompression

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
private static void writeWithCompression(BufferedImage src,
                                         String compression) throws IOException
{
    System.out.println("Compression: " + compression);
    ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
    if (writer == null) {
        throw new RuntimeException("Test failed: no bmp writer available");
    }
    File fout = File.createTempFile(compression + "_", ".bmp",
                                    new File("."));

    ImageOutputStream ios = ImageIO.createImageOutputStream(fout);
    writer.setOutput(ios);

    BMPImageWriteParam param = (BMPImageWriteParam)
            writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionType(compression);
    param.setTopDown(true);
    writer.write(null, new IIOImage(src, null, null), param);
    writer.dispose();
    ios.flush();
    ios.close();

    BufferedImage dst = ImageIO.read(fout);

    verify(dst);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:TopDownTest.java

示例14: test

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的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

示例15: write

import javax.imageio.stream.ImageOutputStream; //导入方法依赖的package包/类
@Override
public void write(BufferedImage image, MediaType contentType, HttpOutputMessage outputMessage)
		throws IOException, HttpMessageNotWritableException {

	if (contentType == null || contentType.isWildcardType() || contentType.isWildcardSubtype()) {
		contentType = getDefaultContentType();
	}
	Assert.notNull(contentType,
			"Count not determine Content-Type, set one using the 'defaultContentType' property");
	outputMessage.getHeaders().setContentType(contentType);
	ImageOutputStream imageOutputStream = null;
	ImageWriter imageWriter = null;
	try {
		imageOutputStream = createImageOutputStream(outputMessage.getBody());
		Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByMIMEType(contentType.toString());
		if (imageWriters.hasNext()) {
			imageWriter = imageWriters.next();
			ImageWriteParam iwp = imageWriter.getDefaultWriteParam();
			process(iwp);
			imageWriter.setOutput(imageOutputStream);
			imageWriter.write(null, new IIOImage(image, null, null), iwp);
		}
		else {
			throw new HttpMessageNotWritableException(
					"Could not find javax.imageio.ImageWriter for Content-Type [" + contentType + "]");
		}
	}
	finally {
		if (imageWriter != null) {
			imageWriter.dispose();
		}
		if (imageOutputStream != null) {
			try {
				imageOutputStream.close();
			}
			catch (IOException ex) {
				// ignore
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:42,代码来源:BufferedImageHttpMessageConverter.java


注:本文中的javax.imageio.stream.ImageOutputStream.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。