當前位置: 首頁>>代碼示例>>Java>>正文


Java MemoryCacheImageOutputStream.flush方法代碼示例

本文整理匯總了Java中javax.imageio.stream.MemoryCacheImageOutputStream.flush方法的典型用法代碼示例。如果您正苦於以下問題:Java MemoryCacheImageOutputStream.flush方法的具體用法?Java MemoryCacheImageOutputStream.flush怎麽用?Java MemoryCacheImageOutputStream.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.imageio.stream.MemoryCacheImageOutputStream的用法示例。


在下文中一共展示了MemoryCacheImageOutputStream.flush方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: timeCLibEncode

import javax.imageio.stream.MemoryCacheImageOutputStream; //導入方法依賴的package包/類
@Test
public void timeCLibEncode() throws Exception {
    ImageWriter writer = new CLibPNGImageWriterSpi().createWriterInstance();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    // Define compression mode
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    // best compression
    // iwp.setCompressionType("FILTERED");
    // we can control quality here
    iwp.setCompressionQuality(0.75f);
    // destination image type
    iwp.setDestinationType(new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel()));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    MemoryCacheImageOutputStream mos = new MemoryCacheImageOutputStream(bos);
    writer.setOutput(mos);
    writer.write(null, new IIOImage(image, null, null), iwp);
    mos.flush();
    collectPng("clib", bos.toByteArray());
    // System.out.println(bos.size());
}
 
開發者ID:aaime,項目名稱:png-experiments,代碼行數:21,代碼來源:BufferedImageEncodingBenchmark.java

示例2: timeCLibEncode

import javax.imageio.stream.MemoryCacheImageOutputStream; //導入方法依賴的package包/類
@Test
public void timeCLibEncode() throws Exception {
    ImageWriter writer = new CLibPNGImageWriterSpi().createWriterInstance();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    // Define compression mode
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    // best compression
    // iwp.setCompressionType("FILTERED");
    // we can control quality here
    iwp.setCompressionQuality((1 - compression / 9f));
    // destination image type
    iwp.setDestinationType(new ImageTypeSpecifier(image.getColorModel(), image.getSampleModel()));
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    MemoryCacheImageOutputStream mos = new MemoryCacheImageOutputStream(bos);
    writer.setOutput(mos);
    writer.write(null, new IIOImage(image, null, null), iwp);
    mos.flush();
    collectPng("clib", bos.toByteArray());
    // System.out.println(bos.size());
}
 
開發者ID:aaime,項目名稱:png-experiments,代碼行數:21,代碼來源:SamplesEncodingBenchmark.java

示例3: writeBinaryData

import javax.imageio.stream.MemoryCacheImageOutputStream; //導入方法依賴的package包/類
/**
* writeBinaryData() method
* Writes results to a Binary file (4-byte float)
*/
static public void writeBinaryData() {
	FileOutputStream fos;
	BufferedOutputStream bos;
	
	try { 
		fos = new FileOutputStream(outputVolume);
		bos = new BufferedOutputStream(fos);
		MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(bos);
		// mcios.setByteOrder(java.nio.ByteOrder.LITTLE_ENDIAN);
		setByteOrder(mcios, byteorder);
		
		//for (int i=0; i < p_values.length; i++) 
			//mcios.writeFloat((float)thresholdedPMap[i]);
		for (int i=0; i < resultsPValues.length; i++) 
			mcios.writeFloat((float)resultsPValues[i]);
			
		System.out.println("Finished Writing out Binary Output\n"
				+"resultsPValues[0]="+resultsPValues[0]
				+"\t resultsPValues["+(resultsPValues.length/2)+"]="
				+resultsPValues[resultsPValues.length/2]);
		mcios.flush();
		mcios.close();
		bos.flush();
		bos.close();
		fos.flush();
		fos.close();
		
	} catch (Exception e) {
		System.out.println("Error in writeBinaryData(): "+e);
	}
	
	return;
}
 
開發者ID:SOCR,項目名稱:HTML5_WebSite,代碼行數:38,代碼來源:Test_FDR.java

示例4: compressAndWriteImage

import javax.imageio.stream.MemoryCacheImageOutputStream; //導入方法依賴的package包/類
private void compressAndWriteImage(BufferedImage bufferedImage, OutputStream outputStream) throws IOException {
  ImageWriter imageWriter = ImageIO.getImageWritersByFormatName("jpg").next();

  ImageWriteParam writeParam = imageWriter.getDefaultWriteParam();
  writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  writeParam.setCompressionQuality(0.90f);

  MemoryCacheImageOutputStream imageOutputStream = new MemoryCacheImageOutputStream(outputStream);
  imageWriter.setOutput(imageOutputStream);
  imageWriter.write(null, new IIOImage(bufferedImage, null, null), writeParam);

  imageOutputStream.flush();
}
 
開發者ID:sigmah-dev,項目名稱:sigmah,代碼行數:14,代碼來源:ImageMinimizer.java

示例5: timeJavaEncode

import javax.imageio.stream.MemoryCacheImageOutputStream; //導入方法依賴的package包/類
@Test
public void timeJavaEncode() throws Exception {
    ImageWriter writer = new PNGImageWriterSpi().createWriterInstance();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    MemoryCacheImageOutputStream mos = new MemoryCacheImageOutputStream(bos);
    writer.setOutput(mos);
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    // iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    // iwp.setCompressionQuality(0.75f);
    writer.write(null, new IIOImage(image, null, null), iwp);
    mos.flush();
    collectPng("java", bos.toByteArray());

    // System.out.println(bos.size());
}
 
開發者ID:aaime,項目名稱:png-experiments,代碼行數:16,代碼來源:BufferedImageEncodingBenchmark.java

示例6: encode

import javax.imageio.stream.MemoryCacheImageOutputStream; //導入方法依賴的package包/類
@Override
public void encode(InputStream rawData, OutputStream encoded, COSDictionary parameters)
        throws IOException
{
    List<byte[]> codeTable = createCodeTable();
    int chunk = 9;

    byte[] inputPattern = null;
    final MemoryCacheImageOutputStream out = new MemoryCacheImageOutputStream(encoded);
    out.writeBits(CLEAR_TABLE, chunk);
    int foundCode = -1;
    int r;
    while ((r = rawData.read()) != -1)
    {
        byte by = (byte) r;
        if (inputPattern == null)
        {
            inputPattern = new byte[] { by };
            foundCode = by & 0xff;
        }
        else
        {
            inputPattern = Arrays.copyOf(inputPattern, inputPattern.length + 1);
            inputPattern[inputPattern.length - 1] = by;
            int newFoundCode = findPatternCode(codeTable, inputPattern);
            if (newFoundCode == -1)
            {
                // use previous
                chunk = calculateChunk(codeTable.size() - 1, 1);
                out.writeBits(foundCode, chunk);
                // create new table entry
                codeTable.add(inputPattern);

                if (codeTable.size() == 4096)
                {
                    // code table is full
                    out.writeBits(CLEAR_TABLE, chunk);
                    codeTable = createCodeTable();
                }

                inputPattern = new byte[] { by };
                foundCode = by & 0xff;
            }
            else
            {
                foundCode = newFoundCode;
            }
        }
    }
    if (foundCode != -1)
    {
        chunk = calculateChunk(codeTable.size() - 1, 1);
        out.writeBits(foundCode, chunk);
    }

    // PPDFBOX-1977: the decoder wouldn't know that the encoder would output 
    // an EOD as code, so he would have increased his own code table and 
    // possibly adjusted the chunk. Therefore, the encoder must behave as 
    // if the code table had just grown and thus it must be checked it is
    // needed to adjust the chunk, based on an increased table size parameter
    chunk = calculateChunk(codeTable.size(), 1);

    out.writeBits(EOD, chunk);
    
    // pad with 0
    out.writeBits(0, 7);
    
    // must do or file will be empty :-(
    out.flush();
    out.close();
}
 
開發者ID:torakiki,項目名稱:sambox,代碼行數:72,代碼來源:LZWFilter.java

示例7: createNewExifNode

import javax.imageio.stream.MemoryCacheImageOutputStream; //導入方法依賴的package包/類
/**
 * Private method - creates a copy of the metadata that can be written to
 * @param tiffMetadata - in metadata
 * @return new metadata node that can be written to
 */
private IIOMetadataNode createNewExifNode( IIOMetadata tiffMetadata, IIOMetadata thumbMeta, BufferedImage thumbnail ) {

    IIOMetadataNode app1Node = null;
    ImageWriter tiffWriter = null;
    try {
        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName("tiff");
        while( writers.hasNext() ) {
            tiffWriter = writers.next();
            if (tiffWriter.getClass().getName().startsWith("com.sun.media")) {
                // Break on finding the core provider.
                break;
            }
        }
        if (tiffWriter == null) {
            System.out.println("Cannot find core TIFF writer!");
            System.exit(0);
        }

        ImageWriteParam writeParam = tiffWriter.getDefaultWriteParam();
        writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        writeParam.setCompressionType("EXIF JPEG");

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        MemoryCacheImageOutputStream app1EXIFOutput = new MemoryCacheImageOutputStream(baos);
        tiffWriter.setOutput(app1EXIFOutput);

        // escribir
        tiffWriter.prepareWriteEmpty(jpegReader.getStreamMetadata(), new ImageTypeSpecifier(image), image.getWidth(),
                image.getHeight(), tiffMetadata, null, writeParam);

        tiffWriter.endWriteEmpty();

        // Flush data into byte stream.
        app1EXIFOutput.flush();

        // Create APP1 parameter array.
        byte[] app1Parameters = new byte[6 + baos.size()];

        // Add EXIF APP1 ID bytes.
        app1Parameters[0] = (byte) 'E';
        app1Parameters[1] = (byte) 'x';
        app1Parameters[2] = (byte) 'i';
        app1Parameters[3] = (byte) 'f';
        app1Parameters[4] = app1Parameters[5] = (byte) 0;

        // Append TIFF stream to APP1 parameters.
        System.arraycopy(baos.toByteArray(), 0, app1Parameters, 6, baos.size());

        // Create the APP1 EXIF node to be added to native JPEG image metadata.
        app1Node = new IIOMetadataNode("unknown");
        app1Node.setAttribute("MarkerTag", (new Integer(0xE1)).toString());
        app1Node.setUserObject(app1Parameters);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (tiffWriter != null)
            tiffWriter.dispose();
    }

    return app1Node;

}
 
開發者ID:TheHortonMachine,項目名稱:hortonmachine,代碼行數:68,代碼來源:ExifGpsWriter.java


注:本文中的javax.imageio.stream.MemoryCacheImageOutputStream.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。