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


Java IIOImage类代码示例

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


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

示例1: compress

import javax.imageio.IIOImage; //导入依赖的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.IIOImage; //导入依赖的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: write

import javax.imageio.IIOImage; //导入依赖的package包/类
@Override
public void write(IIOMetadata streamMetadata, IIOImage image, ImageWriteParam param) throws IOException {
  RenderedImage img = image.getRenderedImage();
  if (stream == null) {
    throw new IOException("Set an output first!");
  }
  if (param == null) {
    param = getDefaultWriteParam();
  }
  Rectangle sourceRegion = new Rectangle(0, 0, img.getWidth(), img.getHeight());
  if (param.getSourceRegion() != null) {
    sourceRegion = sourceRegion.intersection(param.getSourceRegion());
  }
  Raster raster = img.getData(sourceRegion);
  int quality = 85;
  if (param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
    quality = (int) (param.getCompressionQuality() * 100);
  }
  try {
    stream.write(lib.encode(raster, quality).array());
  } catch (TurboJpegException e) {
    throw new IOException(e);
  }
}
 
开发者ID:dbmdz,项目名称:imageio-jnr,代码行数:25,代码来源:TurboJpegImageWriter.java

示例4: convertPngToJpeg

import javax.imageio.IIOImage; //导入依赖的package包/类
private String convertPngToJpeg(String pngBase64) throws IOException {
	byte[] pngBinary = DatatypeConverter.parseBase64Binary(pngBase64);
	InputStream in = new ByteArrayInputStream(pngBinary);
	BufferedImage pngImage = ImageIO.read(in);

	int width = pngImage.getWidth(), height = pngImage.getHeight();
	BufferedImage jpgImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

	Graphics2D g = jpgImage.createGraphics();
	g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
	g.setBackground(Color.WHITE);
	g.clearRect(0, 0, width, height);
	g.drawImage(pngImage, 0, 0, width, height, null);
	g.dispose();

	final ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	writer.setOutput(ImageIO.createImageOutputStream(baos));
	writer.write(null, new IIOImage(jpgImage, null, null), JPEG_PARAMS);

	String jpgBase64 = DatatypeConverter.printBase64Binary(baos.toByteArray());
	return jpgBase64;
}
 
开发者ID:JensN4,项目名称:png_to_jpg_in_svg,代码行数:24,代码来源:PNG_to_JPG_in_SVG.java

示例5: encode

import javax.imageio.IIOImage; //导入依赖的package包/类
/**
 * Encodes an image in JPEG format and writes it to an output stream.
 *
 * @param bufferedImage  the image to be encoded ({@code null} not
 *     permitted).
 * @param outputStream  the OutputStream to write the encoded image to
 *     ({@code null} not permitted).
 *
 * @throws IOException if there is an I/O problem.
 * @throws NullPointerException if {@code bufferedImage} is {@code null}.
 */
@Override
public void encode(BufferedImage bufferedImage, OutputStream outputStream)
        throws IOException {
    Args.nullNotPermitted(bufferedImage, "bufferedImage");
    Args.nullNotPermitted(outputStream, "outputStream");
    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:jfree,项目名称:jfreechart,代码行数:29,代码来源:SunJPEGEncoderAdapter.java

示例6: saveImage

import javax.imageio.IIOImage; //导入依赖的package包/类
public static void saveImage(final String fileName, final BufferedImage image, ImageFormat imageFormat) {
  try {
    final File file = new File(fileName);
    final String extension = FileUtilities.getExtension(fileName);
    Iterator<ImageWriter> iter = null;
    if (canWriteFormat(extension)) {
      iter = ImageIO.getImageWritersByFormatName(extension);
    } else {
      iter = ImageIO.getImageWritersByFormatName(imageFormat.toString());
    }

    final ImageWriter writer = iter.next();
    final ImageWriteParam iwp = writer.getDefaultWriteParam();

    file.getParentFile().mkdirs();
    try (final FileImageOutputStream output = new FileImageOutputStream(file.getAbsoluteFile())) {
      writer.setOutput(output);
      final IIOImage outimage = new IIOImage(image, null, null);
      writer.write(null, outimage, iwp);
      writer.dispose();
    }
  } catch (final IOException e) {
    log.log(Level.SEVERE, e.getMessage(), e);
  }
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:26,代码来源:ImageSerializer.java

示例7: writeJPG

import javax.imageio.IIOImage; //导入依赖的package包/类
public static void writeJPG( BufferedImage rendered, float quality, File f ) {

		try {
			JPEGImageWriteParam jpegParams = new JPEGImageWriteParam( null );
			jpegParams.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
			jpegParams.setCompressionQuality( 1f );

			ImageWriter writer = ImageIO.getImageWritersByFormatName( "jpeg" ).next();
			ImageWriteParam param = writer.getDefaultWriteParam();
			param.setCompressionMode( ImageWriteParam.MODE_EXPLICIT ); // Needed see javadoc
			param.setCompressionQuality( quality ); // Highest quality
			writer.setOutput( new FileImageOutputStream( f ) );
			writer.write( null, new IIOImage( rendered, null, null ), jpegParams );
		} catch ( Throwable th ) {
			th.printStackTrace();
		}
	}
 
开发者ID:twak,项目名称:chordatlas,代码行数:18,代码来源:Imagez.java

示例8: createGif

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

示例9: write

import javax.imageio.IIOImage; //导入依赖的package包/类
public void write(IIOMetadata sm,
                  IIOImage iioimage,
                  ImageWriteParam p) throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (iioimage == null) {
        throw new IllegalArgumentException("iioimage == null!");
    }
    if (iioimage.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }

    resetLocal();

    GIFWritableStreamMetadata streamMetadata;
    if (sm == null) {
        streamMetadata =
            (GIFWritableStreamMetadata)getDefaultStreamMetadata(p);
    } else {
        streamMetadata =
            (GIFWritableStreamMetadata)convertStreamMetadata(sm, p);
    }

    write(true, true, streamMetadata, iioimage, p);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:GIFImageWriter.java

示例10: writeToSequence

import javax.imageio.IIOImage; //导入依赖的package包/类
public void writeToSequence(IIOImage image, ImageWriteParam param)
  throws IOException {
    if (stream == null) {
        throw new IllegalStateException("output == null!");
    }
    if (image == null) {
        throw new IllegalArgumentException("image == null!");
    }
    if (image.hasRaster()) {
        throw new UnsupportedOperationException("canWriteRasters() == false!");
    }
    if (!isWritingSequence) {
        throw new IllegalStateException("prepareWriteSequence() was not invoked!");
    }

    write(!wroteSequenceHeader, false, theStreamMetadata,
          image, param);

    if (!wroteSequenceHeader) {
        wroteSequenceHeader = true;
    }

    this.imageIndex++;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:GIFImageWriter.java

示例11: encode

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

示例12: createTestImage

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

示例13: readFrom

import javax.imageio.IIOImage; //导入依赖的package包/类
private static ITXtTest readFrom(File f) {
    try {
        ImageInputStream iis = ImageIO.createImageInputStream(f);
        ImageReader r = ImageIO.getImageReaders(iis).next();
        r.setInput(iis);

        IIOImage dst = r.readAll(0, null);

        // look for iTXt node
        IIOMetadata m = dst.getMetadata();
        Node root = m.getAsTree(m.getNativeMetadataFormatName());
        Node n = root.getFirstChild();
        while (n != null && !"iTXt".equals(n.getNodeName())) {
            n = n.getNextSibling();
        }
        if (n == null) {
            throw new RuntimeException("No iTXt node!");
        }
        ITXtTest t = ITXtTest.getFromNode((IIOMetadataNode)n);
        return t;
    } catch (Throwable e) {
        throw new RuntimeException("Reading test failed.", e);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:ITXtTest.java

示例14: writeImageWithHist

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

示例15: prepareInsertEmpty

import javax.imageio.IIOImage; //导入依赖的package包/类
public void prepareInsertEmpty(int imageIndex,
                               ImageTypeSpecifier imageType,
                               int width,
                               int height,
                               IIOMetadata imageMetadata,
                               List<? extends BufferedImage> thumbnails,
                               ImageWriteParam param) throws IOException {
    checkParamsEmpty(imageType, width, height, thumbnails);

    this.isInsertingEmpty = true;

    SampleModel emptySM = imageType.getSampleModel();
    RenderedImage emptyImage =
        new EmptyImage(0, 0, width, height,
                       0, 0, emptySM.getWidth(), emptySM.getHeight(),
                       emptySM, imageType.getColorModel());

    insert(imageIndex, new IIOImage(emptyImage, null, imageMetadata),
           param, false);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TIFFImageWriter.java


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