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


Java ImageIO.createImageOutputStream方法代码示例

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


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

示例1: compress

import javax.imageio.ImageIO; //导入方法依赖的package包/类
public static byte[] compress(BufferedImage image, float scale) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
    ImageWriter writer = writers.next();
    ImageWriteParam param = writer.getDefaultWriteParam();
    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    param.setCompressionQuality(scale);
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    writer.setOutput(ios);
    writer.write(null, new IIOImage(image, null, null), param);
    byte[] data = baos.toByteArray();
    writer.dispose();
    return data;
}
 
开发者ID:flschiavoni,项目名称:shareMySheet,代码行数:15,代码来源:ImageTransformation.java

示例2: writeTiff

import javax.imageio.ImageIO; //导入方法依赖的package包/类
/**
 * Writes a buffered image to a TIFF output stream.
 * @param image buffered image to write out as a TIFF
 * @param output output stream to write to
 * @throws IOException If there is an error writing to
 * <code>output</code>.
 */
private void writeTiff(BufferedImage image, OutputStream output)
        throws IOException {
    try (ImageOutputStream ios =
            ImageIO.createImageOutputStream(output)) {
        IIORegistry registry = IIORegistry.getDefaultInstance();
        registry.registerServiceProviders(
                ServiceRegistry.lookupProviders(
                        TIFFImageWriterSpi.class));
        TIFFImageWriterSpi spi = registry.getServiceProviderByClass(
                TIFFImageWriterSpi.class);
        TIFFImageWriter writer = new TIFFImageWriter(spi);
        writer.setOutput(ios);
        writer.write(null, new IIOImage(image, null, null), null);
    }
}
 
开发者ID:glencoesoftware,项目名称:omero-ms-pixel-buffer,代码行数:23,代码来源:TileRequestHandler.java

示例3: doTest

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private static void doTest(int mode) {
    String fileFormat = "bmp";
    try {
        ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix(fileFormat).next();
        if(iw == null) {
            throw new RuntimeException("No available image writer for "
                                       + fileFormat
                                       + " Test failed.");
        }

        File file = new File("image." + fileFormat);
        ImageOutputStream ios = ImageIO.createImageOutputStream(file);
        iw.setOutput(ios);

        BufferedImage bimg = new BufferedImage(100,
                                               100, BufferedImage.TYPE_INT_RGB);
        Graphics g = bimg.getGraphics();
        g.setColor(Color.green);
        g.fillRect(0,0,100,100);

        ImageWriteParam param = iw.getDefaultWriteParam();

        param.setCompressionMode(mode);

        IIOMetadata meta = iw.getDefaultImageMetadata(new ImageTypeSpecifier(bimg),
                                                      param);

        IIOImage iioImg = new IIOImage(bimg, null, meta);
        iw.write(null, iioImg, param);
    } catch(Exception e) {
        e.printStackTrace();
        throw new RuntimeException("Test failed.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:CompressionModeTest.java

示例4: saveImage

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private static long saveImage(final BufferedImage image,
                              final ImageWriter writer,
                              final ImageWriteParam writerParams,
                              final String mode,
                              final String suffix) throws IOException
{
    final File imgFile = new File("WriterCompressionTest-"
                                  + mode + '.' + suffix);
    System.out.println("Writing file: " + imgFile.getAbsolutePath());

    final ImageOutputStream imgOutStream
        = ImageIO.createImageOutputStream(new FileOutputStream(imgFile));
    try {
        writer.setOutput(imgOutStream);
        writer.write(null, new IIOImage(image, null, null), writerParams);
    } finally {
        imgOutStream.close();
    }
    return imgFile.length();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ImageWriterCompressionTest.java

示例5: doTest

import javax.imageio.ImageIO; //导入方法依赖的package包/类
protected void doTest() throws IOException {
    BufferedImage biSrc = getSrc();

    ImageWriter writer = ImageIO.getImageWritersByFormatName("GIF").next();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
    writer.setOutput(ios);

    ImageWriteParam writeParam = writer.getDefaultWriteParam();
    IIOMetadata imageMetadata =
        writer.getDefaultImageMetadata(new ImageTypeSpecifier(biSrc), writeParam);

    IIOMetadata streamMetadata = writer.getDefaultStreamMetadata(writeParam);

    IIOImage iioImg = new IIOImage(biSrc, null, imageMetadata);
    writer.write(streamMetadata, iioImg, writeParam);
    ios.close();

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    ImageInputStream iis = ImageIO.createImageInputStream(bais);
    ImageReader reader = ImageIO.getImageReader(writer);
    reader.setInput(iis);
    BufferedImage dst = reader.read(0);

    // do test
    int x = dx / 2;
    int y = height / 2;

    for (int i = 0; i < usedColors.length; i++) {
        int dstRgb = dst.getRGB(x, y);
        System.out.println("dstColor: " + Integer.toHexString(dstRgb));
        int srcRgb = usedColors[i].getRGB();
        System.out.println("srcColor: " + Integer.toHexString(srcRgb));
        if (dstRgb != srcRgb) {
            throw new RuntimeException("wrong color " + i + ": " + Integer.toHexString(dstRgb));
        }
        x += dx;
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:RGBImageTest.java

示例6: setGlitchQuality

import javax.imageio.ImageIO; //导入方法依赖的package包/类
public static byte[] setGlitchQuality(byte[] inputImageBytes, int quality) throws Exception
{
	Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("png");
	ImageWriter writer = (ImageWriter)iter.next();  
	ImageWriteParam iwp = writer.getDefaultWriteParam(); 
    BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(inputImageBytes)); 
    IIOImage image = new IIOImage(originalImage, null, null);
    ByteArrayOutputStream out=new ByteArrayOutputStream();
    ImageOutputStream imageOut=ImageIO.createImageOutputStream(out);
    writer.setOutput(imageOut);  
    writer.write(null, image, iwp);  
    byte[] qualityImageBytes = out.toByteArray();
    return qualityImageBytes;
}
 
开发者ID:scriptkittie,项目名称:GlitchKernel,代码行数:15,代码来源:ImageUtil.java

示例7: IR2F

import javax.imageio.ImageIO; //导入方法依赖的package包/类
public static void IR2F(ImageReader input, String formatname, String output) throws IOException {
	final Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(formatname);
	final ImageWriter writer = writers.next();
	final File f = new File(output);
	final ImageOutputStream ios = ImageIO.createImageOutputStream(f);
	writer.setOutput(ios);
}
 
开发者ID:zylo117,项目名称:SpotSpotter,代码行数:8,代码来源:ImageReader2File.java

示例8: main

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

示例9: print

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

示例10: testWriteRGB

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private File testWriteRGB(String format, int type) throws IOException {

        BufferedImage bi = new BufferedImage(width, height, type);
        Graphics2D g = bi.createGraphics();

        Color white = new Color(255, 255, 255);
        Color red = new Color(255, 0, 0);
        Color green = new Color(0, 255, 0);
        Color blue = new Color(0, 0, 255);

        g.setColor(white);
        g.fillRect(0, 0, width, height);
        g.setColor(red);
        g.fillRect(10, 10, 20, 20);
        g.setColor(green);
        g.fillRect(30, 30, 20, 20);
        g.setColor(blue);
        g.fillRect(50, 50, 20, 20);

        ImageTypeSpecifier spec = new ImageTypeSpecifier(bi);
        Iterator<ImageWriter> writers = ImageIO.getImageWriters(spec, format);
        File file = new File("BitDepth_" + biTypeNames[type] + "." + format);
        if (!writers.hasNext()) {
            System.out.println("\tNo writers available for type " + biTypeNames[type]
                               + " BufferedImage!");
        } else {
            ImageWriter writer = writers.next();
            try (ImageOutputStream out = ImageIO.createImageOutputStream(file)) {
                writer.setOutput(out);
                writer.write(bi);
            } catch (Exception e) {
                System.out.println("\tCan't write a type " +  biTypeNames[type]
                           + " BufferedImage!");
                return null;
            }
        }

        return file;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:BitDepth.java

示例11: main

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

    ImageTypeSpecifier type =
        ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);

    ImageOutputStream ios =
        ImageIO.createImageOutputStream(new File("MergeTreeTest.jpeg"));
    iw.setOutput(ios);

    IIOMetadata meta = iw.getDefaultImageMetadata(type, null);

    boolean isFailed = false;

    String[] fmts = meta.getMetadataFormatNames();
    for (int i=0; i<fmts.length; i++) {
        System.out.print("Format: " + fmts[i] + " ... ");
        Node root = meta.getAsTree(fmts[i]);
        try {
            meta.mergeTree(fmts[i], root);
        } catch (NullPointerException e) {
            throw new RuntimeException("Test failed for format " + fmts[i], e);
        }
        System.out.println("PASSED");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:MergeTreeTest.java

示例12: compressAndCompare

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private void compressAndCompare(String fixtureName, ImageWriteParam param) throws Exception {
  File expected = new File(ClassLoader.getSystemResource("expected/" + fixtureName).getFile());
  BufferedImage in = ImageIO.read(ClassLoader.getSystemResource("lenna.png"));
  ByteArrayOutputStream os = new ByteArrayOutputStream();
  try (ImageOutputStream ios = ImageIO.createImageOutputStream(os)) {
    writer.setOutput(ios);
    writer.write(null, new IIOImage(in, null, null), param);
  }
  os.flush();
  assertThat(sha1digest(new ByteArrayInputStream(os.toByteArray()))).isEqualTo(sha1digest(expected));
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:12,代码来源:OpenJp2ImageWriterTest.java

示例13: initWriter

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private ImageWriter initWriter() throws IOException {
    ImageOutputStream ios =
        ImageIO.createImageOutputStream(new File(fname));
    writer = ImageIO.getImageWritersByFormatName("GIF").next();

    writer.setOutput(ios);

    return writer;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:AnimationTest.java

示例14: write

import javax.imageio.ImageIO; //导入方法依赖的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:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:EncodeSubImageTest.java

示例15: test

import javax.imageio.ImageIO; //导入方法依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
    try {
        file = File.createTempFile("temp", ".img");
        fos = new FileOutputStream(file);
        final ImageOutputStream ios = ImageIO.createImageOutputStream(fos);
        writer.setOutput(ios);
        final IIOMetadata data = writer.getDefaultStreamMetadata(null);

        if (writer.canWriteSequence()) {
            writer.prepareWriteSequence(data);
        } else {
            try {
                writer.prepareWriteSequence(data);
                throw new RuntimeException(
                        "UnsupportedOperationException was not thrown");
            } catch (final UnsupportedOperationException ignored) {
            // expected
            }
        }
    } finally {
        writer.dispose();
        if (file != null) {
            if (fos != null) {
                fos.close();
            }
            Files.delete(file.toPath());
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:CanWriteSequence.java


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