本文整理汇总了Java中javax.imageio.stream.MemoryCacheImageOutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryCacheImageOutputStream.close方法的具体用法?Java MemoryCacheImageOutputStream.close怎么用?Java MemoryCacheImageOutputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.imageio.stream.MemoryCacheImageOutputStream
的用法示例。
在下文中一共展示了MemoryCacheImageOutputStream.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: optimizedJpeg
import javax.imageio.stream.MemoryCacheImageOutputStream; //导入方法依赖的package包/类
/**
* @param srcJpeg source jpeg to be optimized
* @param configData used configuration
* @return optimized jpeg with quality reduced to ConfigUtils.jpegQuality
*/
public static byte[] optimizedJpeg(byte[] srcJpeg, ConfigData configData)
{
try
{
Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
ImageWriter imgWriter = (ImageWriter)iter.next();
ImageWriteParam imgWriterParam = imgWriter.getDefaultWriteParam();
imgWriterParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
imgWriterParam.setCompressionQuality(configData.jpegQuality);
ByteArrayOutputStream baos = new ByteArrayOutputStream(srcJpeg.length);
MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(baos);
imgWriter.setOutput(mcios);
ByteArrayInputStream bais = new ByteArrayInputStream(srcJpeg);
BufferedImage origBufImage = ImageIO.read(bais);
IIOImage origIioImage = new IIOImage(origBufImage, null, null);
imgWriter.write(null, origIioImage, imgWriterParam);
imgWriter.dispose();
byte[] dstJpeg = baos.toByteArray();
mcios.close();
baos.close();
return dstJpeg;
}
catch (IOException exc)
{
return srcJpeg;
}
}
示例2: 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;
}
示例3: toByteArray
import javax.imageio.stream.MemoryCacheImageOutputStream; //导入方法依赖的package包/类
/**
* Convert an {@link Image} to a BMP byte array.
*
* @param image - the image to convert.
* @return The byte array of the image in BMP format.
* @throws VdioException if byte array creation failed
*/
public static byte[] toByteArray(BufferedImage image) throws VdioException
{
ImageWriter writer = ImageIO.getImageWritersByFormatName("BMP").next();
ByteArrayOutputStream out = new ByteArrayOutputStream();
MemoryCacheImageOutputStream imageOut = new MemoryCacheImageOutputStream(out);
writer.setOutput(imageOut);
try
{
writer.write(image);
imageOut.close();
return out.toByteArray();
}
catch (IOException e)
{
try
{
imageOut.close();
}
catch (IOException ex)
{
}
throw new VdioException("Failed to create byte array from image", e);
}
}
示例4: write
import javax.imageio.stream.MemoryCacheImageOutputStream; //导入方法依赖的package包/类
@Override
public void write(Image image, OutputStream out) throws IOException {
javax.imageio.ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
ImageWriteParam params = writer.getDefaultWriteParam();
if (compression < 100) {
params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
params.setCompressionQuality(compression / 100f);
}
if (progressive) {
params.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);
} else {
params.setProgressiveMode(ImageWriteParam.MODE_DISABLED);
}
// in openjdk, awt cannot write out jpegs that have a transparency bit, even if that is set to 255.
// see http://stackoverflow.com/questions/464825/converting-transparent-gif-png-to-jpeg-using-java
// so have to convert to a non alpha type
BufferedImage noAlpha;
if (image.awt().getColorModel().hasAlpha()) {
noAlpha = image.removeTransparency(java.awt.Color.WHITE).toNewBufferedImage(BufferedImage.TYPE_INT_RGB);
} else {
noAlpha = image.awt();
}
MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(out);
writer.setOutput(output);
writer.write(null, new IIOImage(noAlpha, null, null), params);
output.close();
writer.dispose();
IOUtils.closeQuietly(out);
}
示例5: 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();
}