本文整理汇总了Java中javax.imageio.stream.FileCacheImageOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java FileCacheImageOutputStream类的具体用法?Java FileCacheImageOutputStream怎么用?Java FileCacheImageOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileCacheImageOutputStream类属于javax.imageio.stream包,在下文中一共展示了FileCacheImageOutputStream类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
OutputStream ostream = new ByteArrayOutputStream();
File f = null;
FileCacheImageOutputStream fcios =
new FileCacheImageOutputStream(ostream, f);
fcios.writeBit(1);
fcios.write(96);
fcios.seek(0);
int r1 = fcios.read();
if (r1 != 128 ) {
throw new RuntimeException("Failed, first byte is " + r1);
}
int r2 = fcios.read();
if (r2 != 96) {
throw new RuntimeException("Failed, second byte is " + r2);
}
}
示例2: writeImageWithCompression
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
/**
* Writes the image to an output stream
*
* @param img
* @param ext
* @param os
*/
public static void writeImageWithCompression(BufferedImage img, String ext, OutputStream os) {
img = fixImage(img, ext);
try {
Iterator<ImageWriter> i = ImageIO.getImageWritersBySuffix(ext);
ImageWriter jpegWriter = i.next();
// Set the compression quality to 0.8
ImageWriteParam param = jpegWriter.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(getDefaultImageCompression());
// Write the image to a file
FileCacheImageOutputStream out = new FileCacheImageOutputStream(os, getTempImageCacheDir());
jpegWriter.setOutput(out);
jpegWriter.write(null, new IIOImage(img, null, null), param);
jpegWriter.dispose();
out.flush();
out.close();
} catch (IOException e) {
log.error("Failed to save image to stream", e);
}
}
示例3: writeImage
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
public void writeImage(
final BufferedImage sourceImage,
final OutputStream outputStream,
final File cacheDir) throws IOException {
try (
final CloseableImageWriter writer = new CloseableImageWriter("jpg");
// TODO: should this be in-memory?
final ImageOutputStream imageOutputStream = new FileCacheImageOutputStream(outputStream, cacheDir)
) {
writer.setOutput(imageOutputStream);
final BufferedImage resizedImage = this.resizeImage(sourceImage);
final IIOImage outputImage = new IIOImage(resizedImage, null, null);
final ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
param.setCompressionQuality(this.quality);
writer.write(outputImage, param);
}
}
示例4: createImageOutputStream
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
private ImageOutputStream createImageOutputStream(OutputStream os) throws IOException {
if (this.cacheDir != null) {
return new FileCacheImageOutputStream(os, this.cacheDir);
}
else {
return new MemoryCacheImageOutputStream(os);
}
}
示例5: createOutputStreamInstance
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
public ImageOutputStream createOutputStreamInstance(Object output,
boolean useCache,
File cacheDir)
throws IOException {
if (output instanceof OutputStream) {
OutputStream os = (OutputStream)output;
if (useCache) {
return new FileCacheImageOutputStream(os, cacheDir);
} else {
return new MemoryCacheImageOutputStream(os);
}
} else {
throw new IllegalArgumentException();
}
}
示例6: main
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
OutputStream ostream = new ByteArrayOutputStream();
FileCacheImageOutputStream fcios =
new FileCacheImageOutputStream(ostream, null);
test(fcios);
MemoryCacheImageOutputStream mcios =
new MemoryCacheImageOutputStream(ostream);
test(mcios);
}
示例7: createOutputStreamInstance
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
@Override
public ImageOutputStream createOutputStreamInstance(Object output, boolean useCache, File cacheDir) throws IOException {
if (output instanceof OutputStream) {
if (useCache) {
return new FileCacheImageOutputStream((OutputStream) output, cacheDir);
} else {
return new MemoryCacheImageOutputStream((OutputStream) output);
}
}
throw new IllegalArgumentException(Messages.getString("imageio.85"));
}
示例8: createOutputStreamInstance
import javax.imageio.stream.FileCacheImageOutputStream; //导入依赖的package包/类
@Override
public ImageOutputStream createOutputStreamInstance(Object output, boolean useCache, File cacheDir) throws IOException {
if (output instanceof OutputStream) {
if (useCache) {
return new FileCacheImageOutputStream((OutputStream) output, cacheDir);
} else {
return new MemoryCacheImageOutputStream((OutputStream) output);
}
}
throw new IllegalArgumentException("Output is not an instance of OutputStream");
}