将多个byte []写入Response

时间:2017-02-10 15:41:12

标签: c#

我正在通过WebService从网上下载.TIFF图片。我收到的图像为byte []。我想下载这些图像,我正在使用此代码:

Response.ClearContent();
Response.ContentType = MimeType; // images/tiff
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + Convert.ToString(FileName) + "\"");
byte[] FileContent = Convert.FromBase64String(getFileContentAsBase64String()); // Get the file content
Response.BinaryWrite((byte[])FileContent);
Response.Flush();

这与一个文件一起正常工作。我有一个案例,我想要下载多个文件,但将它们显示为一个文件。目前我正在使用此代码,但它没有按预期工作。它正在下载图像,但只是第一个。我不确定第二和第三会发生什么。

long PageNoLong = long.Parse(PageNo);  // Number of pages (files), in this case we have 3                  

Response.ClearContent();
Response.ContentType = MimeType;
string FileName = "filename.tiff";
Response.AddHeader("Content-Disposition", "attachment;filename=\"" + Convert.ToString(FileName) + "\"");

//In this case, the loop loops three times, returning three byte[] which i write to the Response
for (int i = 1; i < PageNoLong+1; i++)
{                                
    byte[] FileContent = Convert.FromBase64String(getFileContentAsBase64String());                                                                                                 
    Response.BinaryWrite((byte[])FileContent);
}

Response.Flush();

如何将这三个字节[]合并到一个.tiff文件中?

1 个答案:

答案 0 :(得分:-1)

首先必须使用其他方法合并图像,然后下载合并的图像。你不能只合并多个byte [],因为它并没有真正组合文件。

想想看,TIFF文件是如何合并的?一个在另一个之上?在彼此旁边?新图像的大小是多少。

请查看以下链接,了解如何在c#

中合并图像

Merging two images in C#/.NET