我正在使用WPF应用程序,并且在其中使用内存流写入方法来编写DICOM数据字节。当试图编写大小超过70 MB的大型DICOM数据时,它会显示类型为
代码片段如下:
System.OutOfMemoryException
的异常。请问是否有任何解决方法。代码片段如下:
try
{
using ( MemoryStream imagememoryStream = new MemoryStream())
{
while (true)
{
// Retrieve the DICOMData.
// data comes as chunks; if file size is larger, multiple RetrieveDICOMData() calls
// has to be raised. the return value specifies whether the chunk is last one or not.
dicomData = dicomService.RetrieveDICOMData( hierarchyInfo );
imagememoryStream.Write( dicomData.DataBytes, 0, dicomData.DataBytes.Length );
if (dicomData.IsLastChunk)
{
// data is smaller; completed reading so, end
break;
}
}
imageData=imagememoryStream.ToArray();
}
return imageData;
}
catch( Exception exception )
{
throw new DataException( exception.StackTrace );
}