웹에 공개되어 있는 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 |
11166 | 정성태 | 3/28/2017 | 20786 | 오류 유형: 382. System.Data.SqlClient.SqlException - Arithmetic overflow error converting IDENTITY to data type int. | |
11165 | 정성태 | 3/27/2017 | 23749 | 오류 유형: 381. Visual C++에서 min, max 함수를 사용한 경우 C2589, C2059 컴파일 오류 발생 | |
11164 | 정성태 | 3/27/2017 | 32312 | VC++: 111. C++ 클래스의 상속에 따른 메모리 구조 [2] | 1 |
11163 | 정성태 | 3/25/2017 | 21831 | VC++: 110. CreateThread Win32 API에 C++ 클래스의 멤버 함수를 전달하는 방법 | 1 |
11162 | 정성태 | 3/24/2017 | 26338 | 오류 유형: 380. Visual Studio 빌드 실패 - The OutputPath property is not set for project | |
11161 | 정성태 | 3/24/2017 | 17763 | 오류 유형: 379. ICOMAdminCatalog.GetCollection 호출 시 0x80070422 예외 발생 | |
11160 | 정성태 | 3/23/2017 | 23794 | .NET Framework: 649. ASP.NET - Server cannot append header after HTTP headers have been sent. (HTTP 헤더를 보낸 후에는 서버에서 헤더를 추가할 수 없습니다.) | 1 |
11159 | 정성태 | 3/23/2017 | 21048 | Windows: 136. Memory-mapped File은 Private Bytes 크기에 포함될까요? | 1 |
11158 | 정성태 | 3/22/2017 | 19648 | 디버깅 기술: 85. Windbg - SOS 디버깅 사례 System.NullReferenceException 예외 추적 | |
11157 | 정성태 | 3/22/2017 | 23022 | .NET Framework: 648. Dictionary<TKey, TValue>를 deep copy하는 방법 | 1 |
11156 | 정성태 | 3/21/2017 | 24541 | .NET Framework: 647. 닷넷(C#) 코드로 인증서 요청 코드 만드는 방법 | 1 |
11155 | 정성태 | 3/21/2017 | 24971 | .NET Framework: 646. SslStream의 CipherAlgorithm 선택이 가능할까요? | 1 |
11154 | 정성태 | 3/5/2017 | 30986 | VC++: 109. DLL에서 STL 객체를 인자/반환값으로 갖는 함수를 제공할 때, 그 함수를 외부에서 사용하는 경우 비정상 종료한다면? [2] | 1 |
11153 | 정성태 | 3/5/2017 | 30849 | VC++: 108. DLL에 정의된 C++ template 클래스의 복사 생성자 문제 | 1 |
11152 | 정성태 | 3/4/2017 | 25557 | VC++: 107. VirtualAlloc, HeapAlloc, GlobalAlloc, LocalAlloc, malloc, new의 차이점 [1] | 1 |
11151 | 정성태 | 3/3/2017 | 25152 | VC++: 106. DLL 개발자가 주의해야 할 Secure CRT 함수 사용 [1] | 1 |
11150 | 정성태 | 2/21/2017 | 20960 | .NET Framework: 645. Visual Studio Fakes 기능에서 Shim... 클래스가 생성되지 않는 경우 [5] | |
11149 | 정성태 | 2/21/2017 | 24852 | 오류 유형: 378. A 64-bit test cannot run in a 32-bit process. Specify platform as X64 to force test run in X64 mode on X64 machine. | |
11148 | 정성태 | 2/20/2017 | 23975 | .NET Framework: 644. AppDomain에 대한 단위 테스트 시 알아야 할 사항 | |
11147 | 정성태 | 2/19/2017 | 22177 | 오류 유형: 377. Windows 10에서 Fake 어셈블리를 생성하는 경우 빌드 시 The type or namespace name '...' does not exist in the namespace 컴파일 오류 발생 | |
11146 | 정성태 | 2/19/2017 | 21814 | 오류 유형: 376. Error VSP1033: The file '...' does not contain a recognized executable image. [2] | |
11145 | 정성태 | 2/16/2017 | 23115 | .NET Framework: 643. 작업자 프로세스(w3wp.exe)가 재시작되는 시점을 알 수 있는 방법 - 두 번째 이야기 [4] | 1 |
11144 | 정성태 | 2/6/2017 | 26588 | .NET Framework: 642. C# 개발자를 위한 Win32 DLL export 함수의 호출 규약 (부록 1) - CallingConvention.StdCall, CallingConvention.Cdecl에 상관없이 왜 호출이 잘 될까요? | 1 |
11143 | 정성태 | 2/5/2017 | 24134 | .NET Framework: 641. [Out] 형식의 int * 인자를 가진 함수에 대한 P/Invoke 호출 방법 | 1 |
11142 | 정성태 | 2/5/2017 | 31951 | .NET Framework: 640. 닷넷 - 배열 크기의 한계 [2] | 1 |
11141 | 정성태 | 1/31/2017 | 26400 | .NET Framework: 639. C# 개발자를 위한 Win32 DLL export 함수의 호출 규약 (4) - CLR JIT 컴파일러의 P/Invoke 호출 규약 [1] | 1 |