Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create TIFF file?
    primarykey
    data
    text
    <p>I need to create many different large tiff files in java for save it as byte array in dataBase. I only managed to copy old file, change it and create new one - but it take too much time to crete the file(TIFFWriter.createTIFFFromImages). what can I do?</p> <pre><code>public byte[] CreateTiff() throws IOException { try{ File orginialFile = new File("../Dist/dist/attachment/orginialTifFile.TIF"); if(orginialFile!=null){ TIFFReader reader = new TIFFReader(orginialFile); int length = reader.countPages(); BufferedImage[] images = new BufferedImage[length]; for (int i = 0; i &lt; length; i++) { images[i] = (BufferedImage)reader.getPage(i); int rgb = 0x000000; // black Random rand = new Random(); int x= rand.nextInt(images[i].getHeight()/2); int y= rand.nextInt(images[i].getWidth()/2); images[i].setRGB(x, y, rgb); } File newAttachmentFile = new File("../Dist/dist/attachment/tempFile.tif"); TIFFWriter.createTIFFFromImages(images, newAttachmentFile); byte[] b= getBytesFromFile(newAttachmentFile); return b; } }catch(Exception e){ System.out.println("failed to add atachment to request"); e.printStackTrace(); return null; } return null; } </code></pre> <p>public static byte[] getBytesFromFile(File file) throws IOException{ InputStream is = new FileInputStream(file); // Get the size of the file long length = file.length();</p> <pre><code> if (length &gt; Integer.MAX_VALUE) { return null; } // Create the byte array to hold the data byte[] bytes = new byte[(int)length]; // Read in the bytes int offset = 0; int numRead = 0; while (offset &lt; bytes.length &amp;&amp; (numRead=is.read(bytes, offset, bytes.length-offset)) &gt;= 0) { offset += numRead; } // Ensure all the bytes have been read in if (offset &lt; bytes.length) { return null; } // Close the input stream and return bytes is.close(); return bytes; } </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload