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


Java ImageWriter.setOutput方法代码示例

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


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

示例1: saveImage

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

示例2: createGif

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

import javax.imageio.ImageWriter; //导入方法依赖的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:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:OutputImageTests.java

示例4: compressSave

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public void compressSave(MultipartFile file, String uploadLocation) throws IOException {
    //Compresses JPG file but kills the quality.
    BufferedImage image = ImageIO.read(new ByteArrayInputStream(file.getBytes()));
    File compressedImageFile = new File(uploadLocation);
    OutputStream os = new FileOutputStream(compressedImageFile);
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("jpg");
    ImageWriter writer = (ImageWriter) writers.next();
    ImageOutputStream ios = ImageIO.createImageOutputStream(os);
    writer.setOutput(ios);
    ImageWriteParam param = writer.getDefaultWriteParam();
    if(param.canWriteCompressed()) {
        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionQuality(0.05f);
    }

    writer.write(null, new IIOImage(image, null, null), param);
}
 
开发者ID:Exercon,项目名称:AntiSocial-Platform,代码行数:18,代码来源:ImageServiceImpl.java

示例5: createTestImage

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

示例6: test

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void test(final ImageWriter writer) throws Exception {
    final File file = File.createTempFile("temp", ".img");
    file.deleteOnExit();
    final FileOutputStream 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
        }
    }
    writer.dispose();
    ios.close();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:CanWriteSequence.java

示例7: setGlitchQuality

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

示例8: apply

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
@Override
public BufferedImage apply(BufferedImage img) {

	if(compressionLevel == 0f)
		return img;
	
	try {
		ImageWriter iw = ImageIO.getImageWritersByFormatName("jpeg").next();
		JPEGImageWriteParam iwp = (JPEGImageWriteParam) iw.getDefaultWriteParam();
		iwp.setOptimizeHuffmanTables(false);
		iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
		iwp.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
		iwp.setCompressionQuality(1f-compressionLevel);


		ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
		iw.setOutput(new MemoryCacheImageOutputStream(baos)); 

		IIOImage outputImage = new IIOImage(img, null, null);
		iw.write(null, outputImage, iwp);
		iw.dispose();
		
		baos.flush(); 
		byte[] returnImage = baos.toByteArray(); 
		baos.close();
		
		
		BufferedImage img2 = ImageIO.read(new ByteArrayInputStream(returnImage));
		
		if(img2 == null)
			throw new Exception();
		else
			img = img2;

	} catch (Exception e) {
		e.printStackTrace();
	}

	return img;
}
 
开发者ID:CalebKussmaul,项目名称:GIFKR,代码行数:41,代码来源:JPEGFilter.java

示例9: IR2F

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

示例10: test

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

示例11: writeTestImage

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void writeTestImage(String fileName) {
    BufferedImage bi =
        new BufferedImage(TEST_W, TEST_H, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    g.setColor(new Color(testRGB));
    g.fillRect(0, 0, TEST_W, TEST_H);
    try {
        System.err.printf("Writing %s\n", fileName);
        if (lowCompression) {
            ImageWriter iw = (ImageWriter)ImageIO.getImageWritersBySuffix("jpeg").next();
            if(iw == null) {
                throw new RuntimeException("No available image writer for "
                                           + "jpeg "
                                           + " Test failed.");
            }

            File file = new File(fileName);
            ImageOutputStream ios = ImageIO.createImageOutputStream(file);
            iw.setOutput(ios);

            ImageWriteParam param = iw.getDefaultWriteParam();
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            param.setCompressionQuality(1);

            IIOImage iioImg = new IIOImage(bi, null, null);
            iw.write(null, iioImg, param);

        } else {
            ImageIO.write(bi, "jpeg", new File(fileName));
        }
    } catch (IOException e) {
        System.err.println("Error " + e +
                           " when writing file: " + fileName);
        throw new RuntimeException(e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:JPEGsNotAcceleratedTest.java

示例12: writeTo

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
private static void writeTo(File f, ITXtTest t) {
    BufferedImage src = createBufferedImage();
    try {
        ImageOutputStream imageOutputStream =
            ImageIO.createImageOutputStream(f);

        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(src);
        ImageWriter imageWriter =
            ImageIO.getImageWritersByFormatName("PNG").next();

        imageWriter.setOutput(imageOutputStream);

        IIOMetadata m =
            imageWriter.getDefaultImageMetadata(imageTypeSpecifier, null);

        String format = m.getNativeMetadataFormatName();
        Node root = m.getAsTree(format);

        IIOMetadataNode iTXt = t.getNode();
        root.appendChild(iTXt);
        m.setFromTree(format, root);

        imageWriter.write(new IIOImage(src, null, m));
        imageOutputStream.close();
        System.out.println("Writing done.");
    } catch (Throwable e) {
        throw new RuntimeException("Writing test failed.", e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:ITXtTest.java

示例13: print

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

示例14: main

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    ImageWriter iw = new PNGImageWriter(null);
    File f = File.createTempFile("imageio", "tmp");
    ImageOutputStream ios = ImageIO.createImageOutputStream(f);
    try {
        iw.setOutput(ios);
    } catch (NullPointerException npe) {
        f.delete();
        throw new RuntimeException("Got NullPointerException!");
    }
    f.delete();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:SetOutput.java

示例15: main

import javax.imageio.ImageWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    String format = "GIF";
    ImageWriter writer =
            ImageIO.getImageWritersByFormatName(format).next();
    if (writer == null) {
        throw new RuntimeException("No available writers for " + format);
    }

    BufferedImage img = createTestImage(100, 100, BufferedImage.TYPE_BYTE_GRAY);

    ImageWriteParam p = writer.getDefaultWriteParam();
    ImageTypeSpecifier type =
        ImageTypeSpecifier.createFromRenderedImage(img);
    IIOMetadata inImageMetadata =
        writer.getDefaultImageMetadata(type, p);

    IIOMetadata inStreamMetadata = writer.getDefaultStreamMetadata(p);

    // write and read image
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

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

    writer.write(inStreamMetadata, new IIOImage(img, null, inImageMetadata), p);

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

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

    IIOMetadata outStreamMetadata = reader.getStreamMetadata();

    GIFStreamMetadata gifStreamMetadata = (GIFStreamMetadata)outStreamMetadata;

    if (gifStreamMetadata.logicalScreenWidth != img.getWidth() ||
            gifStreamMetadata.logicalScreenHeight != img.getHeight()) {
        throw new RuntimeException("Test failed due to wrong logical screen dimension.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:LogicalScreenDimensionTest.java


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