웹에 공개되어 있는 Sept '05 WinFX CTP 예제가 아래와 같습니다.
// Save XPS Document page(s) to .bmp
// Current as of Sept '05 WinFX CTP
using System.IO;
using System.Windows.Documents;
using System.Windows.Xps.Packaging;
using System.Windows.Media.Imaging;
namespace GenerateXpsBitmaps
{
static public class XpsBitmapHelper
{
static public void SaveXpsPageToBitmap(string xpsFileName, int[] pages)
{
XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read);
FixedDocumentSequence docSeq = xpsDoc.GetPackageRoot();
// You can get the total page count from docSeq.PageCount
foreach (int pageNum in pages)
{
DocumentPage docPage = docSeq.GetPage(pageNum);
BitmapImage bitmap = new BitmapImage();
RenderTargetBitmap renderTarget =
new RenderTargetBitmap( (int) docPage.Size.Width,
(int) docPage.Size.Height,
96, // WPF (Avalon) units are 96dpi based
96,
System.Windows.Media.PixelFormats.Bgra32);
renderTarget.Render(docPage.Visual);
BitmapEncoder encoder = new BmpBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc
encoder.Frames.Add(BitmapFrame.Create(renderTarget));
FileStream pageOutStream = new FileStream(xpsDoc + ".Page" + pageNum + ".bmp", FileMode.Create, FileAccess.Write);
encoder.Save(pageOutStream);
pageOutStream.Close();
}
}
}
}
물론,,, ^^; Feb '06 WinFX CTP에서는 위의 코드가 정상적으로 동작하지 않습니다.
아래의 코드와 같이 변경이 되었기 때문입니다.
또한, 정식 릴리즈되는 WinFX 버전에서는 아래의 코드도 동작하지 않을 것입니다. 참고하십시오. ^^
using System.IO;
using System.Windows.Documents;
using System.Windows.Xps.Packaging;
using System.Windows.Media.Imaging;
using System.Windows.Xps.Serialization;
namespace WindowsApplication1
{
public class XpsBitmapHelper
{
static public void SaveXpsPageToBitmap(string xpsFileName, int[] pages)
{
XpsDocument xpsDoc = new XpsDocument(xpsFileName, System.IO.FileAccess.Read);
FixedDocumentSequence fixedDocumentSeq = xpsDoc.GetFixedDocumentSequence();
for ( int i = 0; i < fixedDocumentSeq.DocumentPaginator.PageCount; i ++ )
{
DocumentPage aPage = fixedDocumentSeq.DocumentPaginator.GetPage( i );
BitmapImage bitmap = new BitmapImage();
RenderTargetBitmap renderTarget =
new RenderTargetBitmap((int)aPage.Size.Width,
(int)aPage.Size.Height,
96, // WPF (Avalon) units are 96dpi based
96,
System.Windows.Media.PixelFormats.Default);
renderTarget.Render(aPage.Visual);
BitmapEncoder encoder = new BmpBitmapEncoder(); // Choose type here ie: JpegBitmapEncoder, etc
encoder.Frames.Add(BitmapFrame.Create(renderTarget));
FileStream pageOutStream = new FileStream(xpsDoc + ".Page" + i.ToString() + ".bmp", FileMode.Create, FileAccess.Write);
encoder.Save(pageOutStream);
pageOutStream.Close();
}
}
}
}
Title |
11903 | 정성태 | 5/21/2019 | 22109 | 오류 유형: 540. .NET Core - System.PlatformNotSupportedException: The named version of this synchronization primitive is not supported on this platform. | |
11902 | 정성태 | 5/21/2019 | 19365 | 오류 유형: 539. mstest 실행 시 "The directory name is invalid." 오류 발생 | |
11901 | 정성태 | 5/21/2019 | 22268 | 오류 유형: 538. msbuild 오류 - Could not find a part of the path '%LOCALAPPDATA%\Temp\2\.NETFramework,Version=v4.0.AssemblyAttributes.cs' | |
11900 | 정성태 | 5/18/2019 | 21031 | 오류 유형: 537. "sfc /scannow" 실행 중 시스템이 부팅되는 현상 | |
11899 | 정성태 | 5/17/2019 | 21520 | Linux: 9. Linux에서 윈도우의 OutputDebugString 대신 사용할 수 있는 syslog [1] | |
11898 | 정성태 | 5/16/2019 | 23082 | VC++: 130. C++ string의 c_str과 data 함수의 차이점 [3] | |
11897 | 정성태 | 5/16/2019 | 29730 | 오류 유형: 536. Visual Studio - "Developer Pack"을 설치했는데도 "대상 프레임워크" 목록에 나오지 않는 경우 [2] | |
11896 | 정성태 | 5/15/2019 | 25748 | 개발 환경 구성: 440. C#, C++ - double의 Infinity, NaN 표현 방식 | 1 |
11895 | 정성태 | 5/12/2019 | 23021 | .NET Framework: 832. ML.NET Model Builder - 회귀(Regression), 다중 분류(Multi-class classification) 예제 | 1 |
11894 | 정성태 | 5/10/2019 | 25086 | VS.NET IDE: 135. Visual Studio - ML.NET Model Builder 소개 [5] | |
11893 | 정성태 | 5/10/2019 | 20968 | 오류 유형: 535. C# 6.0 이상의 문법을 컴파일 시 오류가 발생한다면? | |
11892 | 정성태 | 5/10/2019 | 20784 | 웹: 38. HTTP Cookie의 expires 시간 형식(RFC7231) | |
11891 | 정성태 | 5/9/2019 | 23952 | .NET Framework: 831. (번역글) .NET Internals Cookbook Part 12 - Memory structure, attributes, handles | |
11890 | 정성태 | 5/8/2019 | 19876 | 개발 환경 구성: 439. "Visual Studio Enterprise is required to execute the test." 메시지와 관련된 코드 기록 | |
11889 | 정성태 | 5/8/2019 | 19705 | 개발 환경 구성: 438. mstest, QTAgent의 로그 파일 설정 방법 | |
11888 | 정성태 | 5/8/2019 | 37825 | .NET Framework: 830. C# - 비동기 호출을 취소하는 CancellationToken의 간단한 예제 코드 [1] | 1 |
11887 | 정성태 | 5/8/2019 | 23699 | .NET Framework: 829. C# - yield 문을 사용할 수 있는 메서드의 조건 | |
11886 | 정성태 | 5/7/2019 | 20479 | 오류 유형: 534. mstest.exe 실행 시 "Visual Studio Enterprise is required to execute the test." 오류 [2] | |
11885 | 정성태 | 5/7/2019 | 18180 | 오류 유형: 533. mstest.exe 실행 시 "File extension specified '.loadtest' is not a valid test extension." 오류 발생 | |
11884 | 정성태 | 5/5/2019 | 23160 | .NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기 | |
11883 | 정성태 | 5/3/2019 | 28090 | .NET Framework: 827. C# - 인터넷 시간 서버로부터 받은 시간을 윈도우에 적용하는 방법 | 1 |
11882 | 정성태 | 5/2/2019 | 24733 | .NET Framework: 826. (번역글) .NET Internals Cookbook Part 11 - Various C# riddles | 1 |
11881 | 정성태 | 4/28/2019 | 24834 | 오류 유형: 532. .NET Core 프로젝트로 마이그레이션 시 "CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute" 오류 발생 | |
11880 | 정성태 | 4/25/2019 | 20510 | 오류 유형: 531. 이벤트 로그 오류 - Task Scheduling Error: m->NextScheduledSPRetry 1547, m->NextScheduledEvent 1547 | |
11879 | 정성태 | 4/24/2019 | 29827 | .NET Framework: 825. (번역글) .NET Internals Cookbook Part 10 - Threads, Tasks, asynchronous code and others | 2 |
11878 | 정성태 | 4/22/2019 | 24664 | .NET Framework: 824. (번역글) .NET Internals Cookbook Part 9 - Finalizers, queues, card tables and other GC stuff | 1 |