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


Java ImageOutputStream类代码示例

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


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

示例1: compress

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

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    super.write(ios, writer); // width and height
    // Write the palette (must be 768 bytes)
    byte [] palette = new byte[768];
    IndexColorModel icm = (IndexColorModel) thumbnail.getColorModel();
    byte [] reds = new byte [256];
    byte [] greens = new byte [256];
    byte [] blues = new byte [256];
    icm.getReds(reds);
    icm.getGreens(greens);
    icm.getBlues(blues);
    for (int i = 0; i < 256; i++) {
        palette[i*3] = reds[i];
        palette[i*3+1] = greens[i];
        palette[i*3+2] = blues[i];
    }
    ios.write(palette);
    writePixels(ios, writer);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:JFIFMarkerSegment.java

示例3: save

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
void save(File file) throws IOException {
    ImageWriter iw = null;
    String name = file.getName();
    int i = name.lastIndexOf('.');
    if (i >= 0) {
        String extension = name.substring(i + 1);
        Iterator<ImageWriter> imageWritersBySuffix = ImageIO.getImageWritersBySuffix(extension);
        if (imageWritersBySuffix.hasNext()) {
            iw = imageWritersBySuffix.next();
        }
    }
    if (iw != null) {
        file.delete();
        ImageOutputStream ios = ImageIO.createImageOutputStream(file);
        iw.setOutput(ios);
        try {
            iw.write((BufferedImage) image);
        } finally {
            iw.dispose();
            ios.flush();
            ios.close();
        }
    } else {
        ImageIO.write((BufferedImage) image, "PNG", file);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ScreenshotComponent.java

示例4: convertToPNG

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
private static byte[] convertToPNG(Image image) {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   int width = image.getWidth(null);
   int height = image.getHeight(null);
   BufferedImage bi = new BufferedImage(width, height,
                                        BufferedImage.TYPE_INT_ARGB);
   Graphics2D g = bi.createGraphics();
   g.setComposite(AlphaComposite.Src);
   g.drawImage(image, 0, 0, null);
   g.dispose();
   ImageOutputStream ios = new MemoryCacheImageOutputStream(out);
   try {
      if (!ImageIO.write(bi, "PNG", ios)) {
         throw new IOException("ImageIO.write failed");
      }
      ios.close();
   } catch (IOException ex) {
      throw new RuntimeException("saveImage: " + ex.getMessage());
   }
   return out.toByteArray();
}
 
开发者ID:eric-roberts,项目名称:JavaPPTX,代码行数:22,代码来源:PPPicture.java

示例5: 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

示例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:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:OutputImageTests.java

示例7: verify

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
private static void verify(ImageOutputStream ios,
                           long expstreampos, int expbitoffset)
    throws IOException, RuntimeException
{
    long actstreampos = ios.getStreamPosition();
    int actbitoffset = ios.getBitOffset();

    if ((actstreampos != expstreampos) ||
        (actbitoffset != expbitoffset))
    {
        System.err.println("Expected stream position: " + expstreampos +
                           " Actual: " + actstreampos);
        System.err.println("Expected bit offset: " + expbitoffset +
                           " Actual: " + actbitoffset);
        throw new RuntimeException("Test failed.");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:WriteBitsTest.java

示例8: writeJFXXSegment

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
/**
 * Writes out a new JFXX extension segment, without saving it.
 */
private void writeJFXXSegment(int index,
                              BufferedImage thumbnail,
                              ImageOutputStream ios,
                              JPEGImageWriter writer) throws IOException {
    JFIFExtensionMarkerSegment jfxx = null;
    try {
         jfxx = new JFIFExtensionMarkerSegment(thumbnail);
    } catch (IllegalThumbException e) {
        writer.warningOccurred
            (JPEGImageWriter.WARNING_ILLEGAL_THUMBNAIL);
        return;
    }
    writer.thumbnailStarted(index);
    jfxx.write(ios, writer);
    writer.thumbnailComplete();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:JFIFMarkerSegment.java

示例9: TIFFImageWriterSpi

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
public TIFFImageWriterSpi() {
    super("Oracle Corporation",
          "1.0",
          new String[] {"tif", "TIF", "tiff", "TIFF"},
          new String[] {"tif", "tiff"},
          new String[] {"image/tiff"},
          "com.sun.imageio.plugins.tiff.TIFFImageWriter",
          new Class<?>[] {ImageOutputStream.class},
          new String[] {"com.sun.imageio.plugins.tiff.TIFFImageReaderSpi"},
          false,
          TIFFStreamMetadata.NATIVE_METADATA_FORMAT_NAME,
          "com.sun.imageio.plugins.tiff.TIFFStreamMetadataFormat",
          null, null,
          false,
          TIFFImageMetadata.NATIVE_METADATA_FORMAT_NAME,
          "com.sun.imageio.plugins.tiff.TIFFImageMetadataFormat",
          null, null
          );
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TIFFImageWriterSpi.java

示例10: doTest

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

示例11: write

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
void write(ImageOutputStream ios,
           JPEGImageWriter writer) throws IOException {
    int progInterval = data.length / 20;  // approx. every 5%
    if (progInterval == 0) {
        progInterval = 1;
    }
    for (int offset = 0;
         offset < data.length;) {
        int len = Math.min(progInterval, data.length-offset);
        ios.write(data, offset, len);
        offset += progInterval;
        float percentDone = ((float) offset * 100) / data.length;
        if (percentDone > 100.0F) {
            percentDone = 100.0F;
        }
        writer.thumbnailProgress (percentDone);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:JFIFMarkerSegment.java

示例12: GIFImageWriterSpi

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
public GIFImageWriterSpi() {
    super(vendorName,
          version,
          names,
          suffixes,
          MIMETypes,
          writerClassName,
          new Class[] { ImageOutputStream.class },
          readerSpiNames,
          true,
          GIFWritableStreamMetadata.NATIVE_FORMAT_NAME,
          "com.sun.imageio.plugins.gif.GIFStreamMetadataFormat",
          null, null,
          true,
          GIFWritableImageMetadata.NATIVE_FORMAT_NAME,
          "com.sun.imageio.plugins.gif.GIFImageMetadataFormat",
          null, null
          );
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:GIFImageWriterSpi.java

示例13: compress

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
/**
 * 根据质量压缩图片,不改变图片的尺寸
 * 
 * @param imgContent
 *            图片内容
 * @param quality
 *            缩放比例
 * @param extName
 *            后缀名
 * @return
 */
public byte[] compress(byte[] imgContent, float quality, String extName) {
	if (quality > 1 || quality <= 0 || imgContent == null || WakaUtils.string.isEmpty(extName)) {
		throw new ZhhrUtilException("压缩文件失败!入参为空");
	}
	try (InputStream is = new ByteArrayInputStream(imgContent);
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			ImageOutputStream ios = ImageIO.createImageOutputStream(os);) {
		BufferedImage image = ImageIO.read(is);

		Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(extName);
		ImageWriter writer = writers.next();
		writer.setOutput(ios);

		ImageWriteParam param = writer.getDefaultWriteParam();
		param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
		param.setCompressionQuality(quality);

		writer.write(null, new IIOImage(image, null, null), param);
		writer.dispose();

		return os.toByteArray();
	} catch (IOException e) {
		throw new ZhhrUtilException(e.getMessage(), e);
	}
}
 
开发者ID:wooui,项目名称:springboot-training,代码行数:37,代码来源:ImageUtil.java

示例14: BMPImageWriterSpi

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
public BMPImageWriterSpi() {
    super("Oracle Corporation",
          "1.0",
          formatNames,
          entensions,
          mimeType,
          "com.sun.imageio.plugins.bmp.BMPImageWriter",
          new Class[] { ImageOutputStream.class },
          readerSpiNames,
          false,
          null, null, null, null,
          true,
          BMPMetadata.nativeMetadataFormatName,
          "com.sun.imageio.plugins.bmp.BMPMetadataFormat",
          null, null);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:BMPImageWriterSpi.java

示例15: LZWCompressor

import javax.imageio.stream.ImageOutputStream; //导入依赖的package包/类
/**
 * @param out destination for compressed data
 * @param codeSize the initial code size for the LZW compressor
 * @param TIFF flag indicating that TIFF lzw fudge needs to be applied
 * @exception IOException if underlying output stream error
 **/
public LZWCompressor(ImageOutputStream out, int codeSize, boolean TIFF)
    throws IOException
{
    bf = new BitFile(out, !TIFF); // set flag for GIF as NOT tiff
    this.codeSize = codeSize;
    tiffFudge = TIFF;
    clearCode = 1 << codeSize;
    endOfInfo = clearCode + 1;
    numBits = codeSize + 1;

    limit = (1 << numBits) - 1;
    if (tiffFudge) {
        --limit;
    }

    prefix = (short)0xFFFF;
    lzss = new LZWStringTable();
    lzss.clearTable(codeSize);
    bf.writeBits(clearCode, numBits);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:LZWCompressor.java


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