private static PDImageXObject createFromGrayImage(BufferedImage image, PDDocument document) throws IOException { int height = image.getHeight(); int width = image.getWidth(); int[] rgbLineBuffer = new int[width]; int bpc = image.getColorModel().getPixelSize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(((width*bpc/8)+(width*bpc%8 != 0 ? 1:0))*height); try (MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(baos)) { for (int y = 0; y < height; ++y) { for (int pixel : image.getRGB(0, y, width, 1, rgbLineBuffer, 0, width)) { mcios.writeBits(pixel & 0xFF, bpc); } int bitOffset = mcios.getBitOffset(); if (bitOffset != 0) { mcios.writeBits(0, 8 - bitOffset); } } mcios.flush(); } return prepareImageXObject(document, baos.toByteArray(), image.getWidth(), image.getHeight(), bpc, PDDeviceGray.INSTANCE); }
mcios.flush();
out.flush();
MemoryCacheImageOutputStream byteArrayO = new MemoryCacheImageOutputStream(socket.getOutputStream()); ImageIO.write(screenShot, "PNG", byteArrayO); byteArrayO.flush(); socket.close();
mciis.flush(); bufferedImage.flush();
/** * Writes the bits (if any) before to flush the stream. */ @Override public void flush() throws IOException { flushBits(); super.flush(); }
private static PDImageXObject createFromGrayImage(BufferedImage image, PDDocument document) throws IOException { int height = image.getHeight(); int width = image.getWidth(); int[] rgbLineBuffer = new int[width]; int bpc = image.getColorModel().getPixelSize(); ByteArrayOutputStream baos = new ByteArrayOutputStream(((width*bpc/8)+(width*bpc%8 != 0 ? 1:0))*height); MemoryCacheImageOutputStream mcios = new MemoryCacheImageOutputStream(baos); for (int y = 0; y < height; ++y) { for (int pixel : image.getRGB(0, y, width, 1, rgbLineBuffer, 0, width)) { mcios.writeBits(pixel & 0xFF, bpc); } int bitOffset = mcios.getBitOffset(); if (bitOffset != 0) { mcios.writeBits(0, 8 - bitOffset); } } mcios.flush(); mcios.close(); return prepareImageXObject(document, baos.toByteArray(), image.getWidth(), image.getHeight(), bpc, PDDeviceGray.INSTANCE); }
mcios.flush(); mcios.close();
private Resource getAsResource(BufferedImage image, ImageMime mime) throws IOException { ImageWriter writer = mime.getImageWriter(image); ByteArrayOutputStream os = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(os); writer.setOutput(ios); writer.write(image); ios.flush(); return new ByteArrayResource(os.toByteArray()); }
memOutStream.flush(); memOutStream.close(); writer.dispose();
try { writer.write(null, new IIOImage(finalImage, null, null), iwp); memOutStream.flush();
public void testWrite() throws Exception { final GeoTiffAscii tiffAscii = new GeoTiffAscii("Alois und Sepp"); final ByteArrayOutputStream os = new ByteArrayOutputStream(); final MemoryCacheImageOutputStream ios = new MemoryCacheImageOutputStream(os); tiffAscii.write(ios); ios.flush(); assertEquals("Alois und Sepp|\u0000", os.toString()); }
writeStream = new MemoryCacheImageOutputStream(byteArrayOutputStream); bandBuffer.writeTo(writeStream); writeStream.flush(); readStream = new MemoryCacheImageInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
out.flush(); out.close();
ios.flush(); byte[] bytes = bout.toByteArray(); return Arrays.copyOfRange(bytes, startOffset, bytes.length);