javax.imageio.stream.FileImageOutputStream Java Examples

The following examples show how to use javax.imageio.stream.FileImageOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FontsTest.java    From mica with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) throws IOException, FontFormatException {
	String path = FontsTest.class.getResource("/").getPath().split("build")[0] + "src/main/resources/fonts/";
	String[] fontNames = new String[] {"001.ttf", "002.ttf", "003.ttf", "004.ttf"};
	BufferedImage image = new BufferedImage(1000, 300, BufferedImage.TYPE_INT_RGB);
	// 获取图形上下文
	Graphics2D graphics = image.createGraphics();
	graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR);
	// 图形抗锯齿
	graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	// 字体抗锯齿
	graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
	graphics.setColor(Color.WHITE);
	graphics.fillRect(0, 0, 1000, 300);
	graphics.setColor(Color.BLACK);
	for (int i = 0; i < fontNames.length; i++) {
		String fontName = fontNames[i];
		Font font = Font.createFont(Font.TRUETYPE_FONT, new File(path + fontName));
		graphics.setFont(font.deriveFont(Font.BOLD, 20F));
		graphics.drawString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-×=?", 20, 50 * (i + 1));
	}
	ImageIO.write(image, "JPEG", new FileImageOutputStream(new File("C:\\Users\\dream.lu\\Desktop\\test\\1.jpg")));
}
 
Example #2
Source File: ImageStreamFromRAF.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        File f = new File("ImageInputStreamFromRAF.tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        ImageInputStream istream = ImageIO.createImageInputStream(raf);
        ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
        f.delete();
        if (istream == null) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
        }
        if (ostream == null) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
        }
        if (!(istream instanceof FileImageInputStream)) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
        }
        if (!(ostream instanceof FileImageOutputStream)) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Unexpected IOException: " + ioe);
    }
}
 
Example #3
Source File: HeatChart.java    From SAX with GNU General Public License v2.0 6 votes vote down vote up
private void saveGraphicJpeg(BufferedImage chart, File outputFile, float quality)
    throws IOException {
  // Setup correct compression for jpeg.
  Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
  ImageWriter writer = (ImageWriter) iter.next();
  ImageWriteParam iwp = writer.getDefaultWriteParam();
  iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
  iwp.setCompressionQuality(quality);

  // Output the image.
  FileImageOutputStream output = new FileImageOutputStream(outputFile);
  writer.setOutput(output);
  IIOImage image = new IIOImage(chart, null, null);
  writer.write(null, image, iwp);
  writer.dispose();

}
 
Example #4
Source File: HeatChart.java    From JuiceboxLegacy with MIT License 6 votes vote down vote up
private void saveGraphicJpeg(BufferedImage chart, File outputFile, float quality) throws IOException {
    // Setup correct compression for jpeg.
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = iter.next();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwp.setCompressionQuality(quality);

    // Output the image.
    FileImageOutputStream output = new FileImageOutputStream(outputFile);
    writer.setOutput(output);
    IIOImage image = new IIOImage(chart, null, null);
    writer.write(null, image, iwp);
    writer.dispose();

}
 
Example #5
Source File: DefaultEmptyChoiceTest.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeDefaultEmptyChoiceToFile(File file, byte tag, short value) throws IOException
{
    final FileImageOutputStream stream = new FileImageOutputStream(file);

    switch (tag)
    {
    case 1:
        stream.writeByte(value);
        break;

    case 2:
        stream.writeShort(value);
        break;

    default:
        break;
    }

    stream.close();
}
 
Example #6
Source File: UInt64ParamChoiceTest.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeUInt64ParamChoiceToFile(File file, BigInteger selector, int value) throws IOException
{
    final FileImageOutputStream stream = new FileImageOutputStream(file);

    if (selector.compareTo(new BigInteger("1")) == 0)
        stream.writeByte(value);
    else if (selector.compareTo(new BigInteger("2")) == 0 || selector.compareTo(new BigInteger("3")) == 0 ||
             selector.compareTo(new BigInteger("4")) == 0)
        stream.writeShort(value);
    else if (selector.compareTo(new BigInteger("5")) == 0 || selector.compareTo(new BigInteger("6")) == 0)
        ;
    else
        stream.writeInt(value);

    stream.close();
}
 
Example #7
Source File: UInt32ParamChoiceTest.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeUInt32ParamChoiceToFile(File file, long selector, int value) throws IOException
{
    final FileImageOutputStream stream = new FileImageOutputStream(file);

    if (selector == 1)
    {
        stream.writeByte(value);
    }
    else if (selector == 2 || selector == 3 || selector == 4)
    {
        stream.writeShort(value);
    }
    else if (selector != 5 && selector != 6)
    {
        stream.writeInt(value);
    }

    stream.close();
}
 
Example #8
Source File: ImageConverter.java    From sc2gears with Apache License 2.0 6 votes vote down vote up
private static void convertImages( final File file ) throws Exception {
	if ( file.isDirectory() ) {
		for ( final File childFile : file.listFiles() )
			convertImages( childFile );
	}
	else {
		final BufferedImage bi = ImageIO.read( file );
		
		// Default quality is not sufficient!
		// ImageIO.write( bi, "JPG", new File( file.getPath().replace( ".png", ".jpg" ) ) );
		
		final ImageWriter     iw  = ImageIO.getImageWritersByFormatName( "jpg" ).next();
		final ImageWriteParam iwp = iw.getDefaultWriteParam();
		
		iwp.setCompressionMode( ImageWriteParam.MODE_EXPLICIT );
		iwp.setCompressionQuality( 0.9f );
		
		iw.setOutput( new FileImageOutputStream( new File( file.getPath().replace( ".png", ".jpg" ) ) ) );
		iw.write( null, new IIOImage( bi , null, null ), iwp );
		iw.dispose();
	}
}
 
Example #9
Source File: UInt16ParamChoiceTest.java    From zserio with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void writeUInt16ParamChoiceToFile(File file, int selector, int value) throws IOException
{
    final FileImageOutputStream stream = new FileImageOutputStream(file);

    switch (selector)
    {
    case 1:
        stream.writeByte(value);
        break;

    case 2:
    case 3:
    case 4:
        stream.writeShort(value);
        break;

    case 5:
    case 6:
        break;

    default:
        stream.writeInt(value);
    }

    stream.close();
}
 
Example #10
Source File: TeXFormula.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void createImage(String format, int style, float size, String out, Color bg, Color fg, boolean transparency) {
    TeXIcon icon = createTeXIcon(style, size);
    icon.setInsets(new Insets(1, 1, 1, 1));
    int w = icon.getIconWidth(), h = icon.getIconHeight();

    BufferedImage image = new BufferedImage(w, h, transparency ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    if (bg != null && !transparency) {
        g2.setColor(bg);
        g2.fillRect(0, 0, w, h);
    }

    icon.setForeground(fg);
    icon.paintIcon(null, g2, 0, 0);
    try {
        FileImageOutputStream imout = new FileImageOutputStream(new File(out));
        ImageIO.write(image, format, imout);
        imout.flush();
        imout.close();
    } catch (IOException ex) {
        System.err.println("I/O error : Cannot generate " + out);
    }

    g2.dispose();
}
 
Example #11
Source File: ImageHelper.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Can change this to choose a better compression level as the default
 * 
 * @param image
 * @param scaledImage
 * @return
 */
private static boolean writeTo(BufferedImage image, File scaledImage, Size scaledSize, String outputFormat) {
    try {
        if (!StringHelper.containsNonWhitespace(outputFormat)) {
            outputFormat = OUTPUT_FORMAT;
        }

        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(outputFormat);
        if (writers.hasNext()) {
            ImageWriter writer = writers.next();
            ImageWriteParam iwp = getOptimizedImageWriteParam(writer, scaledSize);
            IIOImage iiOImage = new IIOImage(image, null, null);
            ImageOutputStream iOut = new FileImageOutputStream(scaledImage);
            writer.setOutput(iOut);
            writer.write(null, iiOImage, iwp);
            writer.dispose();
            iOut.flush();
            iOut.close();
            return true;
        } else {
            return ImageIO.write(image, outputFormat, scaledImage);
        }
    } catch (IOException e) {
        return false;
    }
}
 
Example #12
Source File: HeatChart.java    From Juicebox with MIT License 6 votes vote down vote up
private void saveGraphicJpeg(BufferedImage chart, File outputFile, float quality) throws IOException {
    // Setup correct compression for jpeg.
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpeg");
    ImageWriter writer = iter.next();
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwp.setCompressionQuality(quality);

    // Output the image.
    FileImageOutputStream output = new FileImageOutputStream(outputFile);
    writer.setOutput(output);
    IIOImage image = new IIOImage(chart, null, null);
    writer.write(null, image, iwp);
    writer.dispose();

}
 
Example #13
Source File: FrameExporter.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
public static void makeGIFOld(Iterator<BufferedImage> images, float frameRate, File file, EventListener evl) throws IOException {
    if (!images.hasNext()) {
        return;
    }

    try (ImageOutputStream output = new FileImageOutputStream(file)) {
        BufferedImage img0 = images.next();
        GifSequenceWriter writer = new GifSequenceWriter(output, img0.getType(), (int) (1000.0 / frameRate), true);
        writer.writeToSequence(img0);

        while (images.hasNext()) {
            writer.writeToSequence(images.next());
        }

        writer.close();
    }
}
 
Example #14
Source File: EncodeTest.java    From j-webp with Apache License 2.0 6 votes vote down vote up
public static void main(String args[]) throws IOException {
    String inputPngPath = "test_pic/test.png";
    String inputJpgPath = "test_pic/test.jpg";
    String outputWebpPath = "test_pic/test_.webp";

    // Obtain an image to encode from somewhere
    BufferedImage image = ImageIO.read(new File(inputJpgPath));

    // Obtain a WebP ImageWriter instance
    ImageWriter writer = ImageIO.getImageWritersByMIMEType("image/webp").next();

    // Configure encoding parameters
    WebPWriteParam writeParam = new WebPWriteParam(writer.getLocale());
    writeParam.setCompressionMode(WebPWriteParam.MODE_DEFAULT);

    // Configure the output on the ImageWriter
    writer.setOutput(new FileImageOutputStream(new File(outputWebpPath)));

    // Encode
    long st = System.currentTimeMillis();
    writer.write(null, new IIOImage(image, null, null), writeParam);
    System.out.println("cost: " + (System.currentTimeMillis() - st));
}
 
Example #15
Source File: ImageHelper.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * Can change this to choose a better compression level as the default
 * 
 * @param image
 * @param scaledImage
 * @return
 */
private static boolean writeTo(BufferedImage image, File scaledImage, Size scaledSize, String outputFormat) {
    try {
        if (!StringHelper.containsNonWhitespace(outputFormat)) {
            outputFormat = OUTPUT_FORMAT;
        }

        Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(outputFormat);
        if (writers.hasNext()) {
            ImageWriter writer = writers.next();
            ImageWriteParam iwp = getOptimizedImageWriteParam(writer, scaledSize);
            IIOImage iiOImage = new IIOImage(image, null, null);
            ImageOutputStream iOut = new FileImageOutputStream(scaledImage);
            writer.setOutput(iOut);
            writer.write(null, iiOImage, iwp);
            writer.dispose();
            iOut.flush();
            iOut.close();
            return true;
        } else {
            return ImageIO.write(image, outputFormat, scaledImage);
        }
    } catch (IOException e) {
        return false;
    }
}
 
Example #16
Source File: ImageStreamFromRAF.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
    try {
        File f = new File("ImageInputStreamFromRAF.tmp");
        RandomAccessFile raf = new RandomAccessFile(f, "rw");
        ImageInputStream istream = ImageIO.createImageInputStream(raf);
        ImageOutputStream ostream = ImageIO.createImageOutputStream(raf);
        f.delete();
        if (istream == null) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) returned null!");
        }
        if (ostream == null) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) returned null!");
        }
        if (!(istream instanceof FileImageInputStream)) {
            throw new RuntimeException("ImageIO.createImageInputStream(RandomAccessFile) did not return a FileImageInputStream!");
        }
        if (!(ostream instanceof FileImageOutputStream)) {
            throw new RuntimeException("ImageIO.createImageOutputStream(RandomAccessFile) did not return a FileImageOutputStream!");
        }
    } catch (IOException ioe) {
        throw new RuntimeException("Unexpected IOException: " + ioe);
    }
}
 
Example #17
Source File: PageImageWriter.java    From sejda with GNU Affero General Public License v3.0 6 votes vote down vote up
public static SeekableSource convertImageTo(SeekableSource source, String format) throws IOException, TaskIOException {
    BufferedImage image = ImageIO.read(source.asNewInputStream());
    File tmpFile = IOUtils.createTemporaryBuffer("." + format);
    ImageOutputStream outputStream = new FileImageOutputStream(tmpFile);

    try {
        ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next();
        writer.setOutput(outputStream);
        ImageWriteParam param = writer.getDefaultWriteParam();
        if (format.equals("jpeg")) {
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            param.setCompressionQuality(1.0F);
        }
        writer.write(null, new IIOImage(image, null, null), param);
    } finally {
        org.sejda.commons.util.IOUtils.closeQuietly(outputStream);
    }

    return SeekableSources.seekableSourceFrom(tmpFile);
}
 
Example #18
Source File: FileImageOutputStreamSpi.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #19
Source File: Images.java    From restcommander with Apache License 2.0 5 votes vote down vote up
/**
 * Crop an image
 * @param originalImage The image file
 * @param to The destination file
 * @param x1 The new x origin
 * @param y1 The new y origin
 * @param x2 The new x end
 * @param y2 The new y end
 */
public static void crop(File originalImage, File to, int x1, int y1, int x2, int y2) {
    try {
        BufferedImage source = ImageIO.read(originalImage);

        String mimeType = "image/jpeg";
        if (to.getName().endsWith(".png")) {
            mimeType = "image/png";
        }
        if (to.getName().endsWith(".gif")) {
            mimeType = "image/gif";
        }
        int width = x2 - x1;
        int height = y2 - y1;

        // out
        BufferedImage dest = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Image croppedImage = source.getSubimage(x1, y1, width, height);
        Graphics graphics = dest.getGraphics();
        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, width, height);
        graphics.drawImage(croppedImage, 0, 0, null);
        ImageWriter writer = ImageIO.getImageWritersByMIMEType(mimeType).next();
        ImageWriteParam params = writer.getDefaultWriteParam();
        writer.setOutput(new FileImageOutputStream(to));
        IIOImage image = new IIOImage(dest, null, null);
        writer.write(null, image, params);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}
 
Example #20
Source File: ExifGpsWriter.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Main method to write the gps data to the exif 
 * @param gps - gps position to be added
 * @throws IOException 
 */
private void writeExif() throws IOException {

    IIOMetadata metadata = jpegReader.getImageMetadata(0);

    // names says which exif tree to get - 0 for jpeg 1 for the default
    String[] names = metadata.getMetadataFormatNames();
    IIOMetadataNode root = (IIOMetadataNode) metadata.getAsTree(names[0]);

    // exif is on the app1 node called unknown
    NodeList nList = root.getElementsByTagName("unknown");
    IIOMetadataNode app1EXIFNode = (IIOMetadataNode) nList.item(0);
    ArrayList<IIOMetadata> md = readExif(app1EXIFNode);
    IIOMetadata exifMetadata = md.get(0);

    // insert the gps data into the exif
    exifMetadata = insertGPSCoords(exifMetadata);

    // create a new exif node
    IIOMetadataNode app1NodeNew = createNewExifNode(exifMetadata, null, null);

    // copy the user data accross
    app1EXIFNode.setUserObject(app1NodeNew.getUserObject());

    // write to a new image file
    FileImageOutputStream out1 = new FileImageOutputStream(new File("GPS_" + imageFile.getName()));
    jpegWriter.setOutput(out1);
    metadata.setFromTree(names[0], root);

    IIOImage image = new IIOImage(jpegReader.readAsRenderedImage(0, jpegReader.getDefaultReadParam()), null, metadata);

    // write out the new image
    jpegWriter.write(jpegReader.getStreamMetadata(), image, jpegWriter.getDefaultWriteParam());

}
 
Example #21
Source File: Utils.java    From render with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Saves the specified image to a file using ImageIO.
 */
public static void saveImage(final BufferedImage image,
                             final String pathOrUriString,
                             final String format,
                             final boolean convertToGray,
                             final float quality)
        throws IOException {

    final File file = new File(convertPathOrUriStringToUri(pathOrUriString));

    final File parentDirectory = file.getParentFile();
    if ((parentDirectory != null) && (!parentDirectory.exists())) {
        if (!parentDirectory.mkdirs()) {
            // check for existence again in case another parallel process already created the directory
            if (! parentDirectory.exists()) {
                throw new IllegalArgumentException("failed to create directory " +
                                                   parentDirectory.getAbsolutePath());
            }
        }
    }

    if (TIFF_FORMAT.equals(format) || (TIF_FORMAT.equals(format))) {

        try (final FileOutputStream outputStream = new FileOutputStream(file)) {
            writeTiffImage(image, outputStream);
        }

    } else {

        try (final FileImageOutputStream outputStream = new FileImageOutputStream(file)) {
            writeImage(image, format, convertToGray, quality, outputStream);
        }

    }

    LOG.info("saveImage: exit, saved {}", file.getAbsolutePath());
}
 
Example #22
Source File: FileImageOutputStreamSpi.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #23
Source File: WaveImporter.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private static File writeImage(BufferedImage image, File folder, String filename, ImageMimeType imageType) throws IOException {
    File imgFile = new File(folder, filename);
    FileImageOutputStream fos = new FileImageOutputStream(imgFile);
    try {
        ImageSupport.writeImageToStream(image, imageType.getDefaultFileExtension(), fos, 1.0f);
        return imgFile;
    } finally {
        fos.close();
    }
}
 
Example #24
Source File: ImageHandler.java    From density-converter with Apache License 2.0 5 votes vote down vote up
private void compressJpeg(BufferedImage bufferedImage, CompoundDirectory exif, float quality, File targetFile) throws IOException {
    ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next();
    ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam();
    jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    jpgWriteParam.setCompressionQuality(quality);

    ImageWriter writer = null;
    try (ImageOutputStream outputStream = new FileImageOutputStream(targetFile)) {
        writer = ImageIO.getImageWritersByFormatName("jpg").next();
        writer.setOutput(outputStream);
        writer.write(null, new IIOImage(bufferedImage, null, null), jpgWriteParam);
    } finally {
        if (writer != null) writer.dispose();
    }
}
 
Example #25
Source File: RAFImageOutputStreamSpi.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof RandomAccessFile) {
        try {
            return new FileImageOutputStream((RandomAccessFile)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
Example #26
Source File: ThumbnailatorTest.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Test
public void testOutput() throws IOException {
    final String oldFile = System.getProperty("user.dir") + "/src/test/resources/images/lion2.jpg";
    File file = new File(oldFile);
    BufferedImage bufferedImage = ImageIO.read(file);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    // 输入形式:文件名
    Thumbnails.of(bufferedImage).scale(1.0).outputFormat("png").toOutputStream(outputStream);
    byte[] bytes = outputStream.toByteArray();
    FileImageOutputStream imageOutput = new FileImageOutputStream(new File("d:\\lion_output.png"));
    imageOutput.write(bytes, 0, bytes.length);
    imageOutput.close();
}
 
Example #27
Source File: FileImageOutputStreamSpi.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #28
Source File: RAFImageOutputStreamSpi.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof RandomAccessFile) {
        try {
            return new FileImageOutputStream((RandomAccessFile)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}
 
Example #29
Source File: FileImageOutputStreamSpi.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof File) {
        try {
            return new FileImageOutputStream((File)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException();
    }
}
 
Example #30
Source File: RAFImageOutputStreamSpi.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ImageOutputStream createOutputStreamInstance(Object output,
                                                    boolean useCache,
                                                    File cacheDir) {
    if (output instanceof RandomAccessFile) {
        try {
            return new FileImageOutputStream((RandomAccessFile)output);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    } else {
        throw new IllegalArgumentException
            ("input not a RandomAccessFile!");
    }
}