画像に変換しようとしている XPS ドキュメントに、非常に大きなページ (高さと幅が数万ピクセル、数万のノードとリンクがある) があります。XPS ドキュメントには 1 ページしか含まれていません。
これを行う方法を調査すると、これに関する基本的な方法 (主に他の StackOverflow の質問に基づく) は、次のようになります。
[STAThread]
static void Main(string[] args)
{
XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read);
FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
DocumentPage page = docSeq.DocumentPaginator.GetPage(0);
RenderTargetBitmap renderTarget = new RenderTargetBitmap( (int)page.Size.Width,
(int)page.Size.Height,
96,
96,
PixelFormats.Default);
renderTarget.Render(page.Visual); //The error occurs here
}
Render
その時点で失敗するため、その呼び出しの後に実際の画像エンコーディングとファイル作成のコードは含めていません。
この操作にはかなりの量のメモリが必要であることを認識しているため、64ビットアプリケーションとしてビルドしているため、メモリ不足の例外は発生しません。ビルド マシンのメモリは問題になりません。
私が得るエラーは、次のようSystem.OverflowException
に述べています。
The image data generated an overflow during processing.
さらに、途中で次のような「ContextSwitchDeadlock
」メッセージが表示されます。
The CLR has been unable to transition from COM context 0xfc55d4d8 to COM context 0xfc55d600 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.
私が書いていないコードに消えてしまうため、これについて何ができるかわかりません。これに対処する方法がわかりません。
私の質問は基本的に、1 つ以上の巨大なページを含む XPS ドキュメントを PNG 画像ファイルに変換する方法はありますか? 私が調べようとしたことの 1 つは、RenderTargetBitmap を使用して XPS ページの小さなチャンクのみをレンダリングし、最後にすべてのチャンクを 1 つの画像に結合することですが、その方法を見つけることができませんでした。これ、または可能であれば。