组合多重tiff图像的BASE64图像数据所面临的问题

时间:2018-03-19 08:23:53

标签: c# merge base64 tiff multipage

我遇到了一个需要取出多页tiff图像文件的Base64内容的问题。此图像文件上传到我能够访问它的第三方系统。 这里的图像有两页,我逐页访问它,并将字节数据存储在byte []数组的两个独立索引中。 现在,当我将这两个页面单独转换为相应的基本64内容时,我就是正确的。但我没有得到如何合并两个页面的这两个基本64内容,以获得两个页面的单个基本64内容。

我需要为这两个页面获得base 64字符串。这是代码示例:

// Check if the document type is multi page tiff document
if (workPacket.Folder[documentIndex].DocumentType.Equals(Resources.DocumentTypeMultiPg))
{
    // Convert the document object to Multipage diff object
    MultiPageTiffDocument tiffDoc = (MultiPageTiffDocument)workPacket.Folder[documentIndex].Document;

    int pageCount = tiffDoc.PageCount;

    Helper.LogMessage(string.Format(Helper.UkCulture, Resources.PageCountMsg + pageCount), Helper.BpiMessageLevel4, tasknode);

    bool allOk = false;

    List<byte[]> test = new List<byte[]>();

    for (int page = 1; page <= pageCount; page++)
    {
        if (tiffDoc.CopyImageToFile(page, tempCopyFileName, true))
        {
            allOk = true;

            test.Add(File.ReadAllBytes(tempCopyFileName));

            Helper.LogMessage(string.Format("Data copied for page {0} is {1}", page, File.ReadAllBytes(tempCopyFileName)), Helper.BpiMessageLevel4, tasknode);
        }
    }

    // Copy the document data to temporary file
    if (allOk)
    {
        // Read the data from File created.
        int lngth = 0;

        for (int j = 0; j < test.Count; j++)
        {
            lngth = lngth + test[j].Length;

            Helper.LogMessage(string.Format("Length of {0} element is {1}",j, test[j].Length), Helper.BpiMessageLevel4, tasknode);
        }

        byteData = new byte[lngth];

        int Consolidatelength = 0;

        for (int j = 0; j < test.Count; j++)
        {
            if (j == 0)
            {
                test[j].CopyTo(byteData, 0);
            }
            else
            {
                Consolidatelength = Consolidatelength + test[j - 1].Length;

                test[j].CopyTo(byteData, Consolidatelength);
            }
        }
    }
    else
    {
        Helper.LogMessage(string.Format(Helper.UkCulture, Resources.CopyFailedMsg, tempCopyFileName), Helper.BpiMessageLevel4, tasknode);
    }
}

// Add the combined base 64 in separate collection
binaryCollection.Add(Convert.ToBase64String(byteData));

0 个答案:

没有答案