如果有人在我之后有兴趣,这里是我的发现工作:
for (int i = 0; i < reverseImageFiles.Length; i++)
{
string curBMP = reverseImageFiles[i];
using(Stream inStream = File.OpenRead(curBMP))
using (Stream writeStream = new FileStream(outputBMP,FileMode.Append,FileAccess.Write,FileShare.None))
{
BinaryReader reader = new BinaryReader(inStream);
BinaryWriter writer = new BinaryWriter(writeStream);
byte[] buffer = new Byte[134217728];
int bytesRead;
int totalBytes = 0;
while ((bytesRead = inStream.Read(buffer, 0, 134217728)) > 0)
{
totalBytes += bytesRead;
if (totalBytes <= 134217729) //if it's the first round of reading to the buffer, you need to get rid of 54-byte BMP header
{
writeStream.Write(buffer, 54, bytesRead - 54);
}
else
{
writeStream.Write(buffer, 0, bytesRead);
}
}
}
}
两件事情:
专门为BMP的,我发现,你需要扭转的文件列表追加时。例如,如果要附加的三个文件标记为001.bmp,002.bmp,003.bmp,其中001.bmp应位于最上方,则您需要实际从003.bmp开始并逐渐减少。显然BMP是向后编码的。
正如您所看到的,我使用了一个128MB缓冲区。如果我想降低硬盘驱动器的搜索速度,使用不同的大小会更好吗?我的驱动器最近进行了整理。感谢所有的帮助!
>如何读取每个BMP并将它们追加到最终文件而不使用我所有的内存? 流式传输文件。 – Romoku 2013-03-27 12:55:29