Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

웹에 공개되어 있는 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();
            }
        }
    }
}









[최초 등록일: ]
[최종 수정일: 10/18/2006]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 166  167  [168]  169  170  171  172  173  174  175  176  177  178  179  180  ...
NoWriterDateCnt.TitleFile(s)
871정성태5/13/201035438VC++: 40. MSBuild를 이용한 VC++ 프로젝트 빌드파일 다운로드1
870정성태5/12/201026532제니퍼 .NET: 4. 닷넷 APM 솔루션 - 제니퍼 닷넷의 기능 요약 [2]
869정성태11/8/201927969오류 유형 : 95. WCF 인증서 설정 관련 오류 정리 [4]
865정성태5/5/201030411개발 환경 구성: 75. 인증서의 개인키를 담은 물리 파일 위치 알아내는 방법파일 다운로드1
864정성태5/4/201034173.NET Framework: 178. WCF - 사용자 정의 인증 구현 예제 [4]파일 다운로드1
863정성태5/4/201060112개발 환경 구성: 74. 인증서 관련(CER, PVK, SPC, PFX) 파일 만드는 방법 [1]파일 다운로드1
862정성태5/3/201021944제니퍼 .NET: 3. 제2회 닷넷 개발자 컨퍼런스에서 뵙겠습니다. ^^
861정성태5/1/201022371.NET Framework: 177. .NET 2.0 Profiler에 .NET 4.0 지원 추가
860정성태4/30/201027593오류 유형: 95. .NET 4.0 설치 오류 - 0x800c0005 [1]
858정성태4/29/201031462제니퍼 .NET: 2. JENNIFER .NET을 이용한 .NET 웹 사이트 모니터링 (2) - 설치 [3]
857정성태4/27/201029834제니퍼 .NET: 1. JENNIFER .NET을 이용한 .NET 웹 사이트 모니터링 (1) - 임시 라이선스 요청 및 다운로드
855정성태4/24/201026747.NET Framework: 176. DataContext가 thread-safe한 것인가?
854정성태4/22/201023361오류 유형: 94. 팀 프로젝트 생성 오류 - TF218017, TF250044
853정성태4/22/201024026오류 유형: 93. TFS 2010 오류: rsProcessingAborted, rsErrorExecutingCommand
852정성태4/21/201025294Team Foundation Server: 33. 단일 서버에 Team Foundation Server 2010 설치하는 방법
851정성태4/14/201036131오류 유형: 92. Task Scheduler 오류: 2147942667 (0x8007010B)
850정성태4/7/201024379.NET Framework: 175. WCF - webHttpBinding + PUT 메서드 구현파일 다운로드1
848정성태3/30/201038132개발 환경 구성: 73. 한 대의 PC에서 여러 개의 키입력 매크로 프로그램이 가능할까? [5]파일 다운로드5
846정성태3/29/201035970VC++: 39. C++에서 싱글톤 구현하기 [8]파일 다운로드1
844정성태3/19/201023395개발 환경 구성: 72. Adobe Creative Suite 3 Master Collection - 하드 디스크로부터 설치하는 방법
843정성태3/19/201032437Windows: 50. Windows Server 2008 R2 시스템에 Windows 7 멀티 부팅하는 방법
842정성태3/17/201027909Windows: 49. VHD 파일 지원
841정성태3/16/201028613.NET Framework: 174. 작업자 프로세스(w3wp.exe)가 재시작되는 시점을 알 수 있는 방법 [1]
840정성태3/4/201021968개발 환경 구성: 71. w3wp.exe에 환경 변수 전달하는 방법 [1]
836정성태2/13/201025338VS.NET IDE: 67. Visual Studio 2010: 베타 2에서 RC 마이그레이션
835정성태1/26/201026603.NET Framework: 173. WCF - webHttpBinding + IIS 6.0 윈도우 인증 구현 예제 [3]파일 다운로드1
... 166  167  [168]  169  170  171  172  173  174  175  176  177  178  179  180  ...