本文整理汇总了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());
}
示例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());
}
示例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;
}
示例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();
}
示例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());
}
示例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();
}
示例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;
}