使用java将原始图像字节转换为多页tiff,反之亦然

时间:2017-09-03 13:51:40

标签: java tiff

我有一个要求,我有一组base64字符串,每个字符串是一个tiff文件,我需要组合所有这些base64字符串并提供这个完整的tiff数据作为base64字符串,所以最终用户可以从组合创建一个tiff文件base64字符串。

我尝试了以下共享的所有方式,但每次在我的输出tiff中只有一页即将到来,但我传递了2个base64字符串。

非常感谢任何投入。

我使用此代码

  ArrayList al = new ArrayList();

//this is repetative so i am adding all the base64 strings to arraylist
byte[] imgBytes = Base64.decodeBase64(imageObject.get("image").toString());
                                                                                                  al.add(imgBytes);

//writing all base64 strings to a new tiff file //here it is showing only the first page but in the top i am adding two pages.
BufferedImage imag=ImageIO.read(new ByteArrayInputStream(toByteArray(al)));
                                                                   ImageIO.write(imag, "tif", new File(processedFilesFolder,"combined.tif"));


public static byte[] toByteArray(List<byte[]> bytesList)
{
    int size = 0;

    for (byte[] bytes : bytesList)
    {
        size += bytes.length;
    }

    ByteBuffer byteBuffer = ByteBuffer.allocate(size);

    for (byte[] bytes : bytesList)
    {
        byteBuffer.put(bytes);
    }

    return byteBuffer.array();
}



ByteArrayOutputStream outputStream = new ByteArrayOutputStream( ); 
outputStream.write( data ); // this line is repetative
byte c[] = outputStream.toByteArray( ); 
try (OutputStream stream = new FileOutputStream("C:\\Users\\XYZ\\Desktop\\EID_Image_Desktop‌​Scan_mod.tiff")) { stream.write(c); } catch(Exception e){}

此致 Meerasaaheb Mohmmad

0 个答案:

没有答案