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

비밀번호

댓글 작성자
 




... 181  182  183  184  185  186  187  188  189  190  191  [192]  193  194  195  ...
NoWriterDateCnt.TitleFile(s)
129정성태3/30/200518500    답변글 .NET Framework: 34.1. 위의 질문에 대한 답변으로 나온 것입니다.
130정성태3/30/200515834        답변글 .NET Framework: 34.2. 다시... 제가 질문한 내용입니다. ^^
131정성태3/30/200516321            답변글 .NET Framework: 34.3. 다시... 정봉겸님이 하신... 명확한 답변입니다.
126정성태3/26/200516165.NET Framework: 33. Proxy 환경에서의 Smart Client 업데이트 문제 [1]
133정성태3/31/200517244    답변글 .NET Framework: 33.1. [추가]: Proxy 환경에서의 Smart Client 업데이트 문제 [2]
125정성태3/26/200516235VC++: 15. VC++ Keyword
124정성태3/25/200516790.NET Framework: 32. 네트워크 공유 없이 상대 컴퓨터에 프로그램 설치
119정성태3/21/200516381.NET Framework: 31. 소스세이프 오류현상: 웹 프로젝트를 열수 없습니다.
120정성태3/21/200517685    답변글 .NET Framework: 31.1. 소스세이프 오류현상: PDB 파일이 잠기는 문제
121정성태3/21/200517726    답변글 .NET Framework: 31.2. 소스세이프 오류현상: VS.NET 2003 IDE 와 연동되는 소스세이프 버전 문제
122정성태3/21/200516440    답변글 .NET Framework: 31.3. 소스세이프 관련 사이트
160정성태11/14/200519355    답변글 VS.NET IDE: 31.4. [추가]: 웹 애플리케이션 로드시 "_1"을 붙여서 묻는 경우. [1]
196이문석12/23/200516157        답변글 .NET Framework: 31.8. [답변]: [추가]: 웹 애플리케이션 로드시 "_1" 을 붙여서 묻는 경우.
167정성태10/10/200515701    답변글 .NET Framework: 31.5. [추가]: 삭제한 웹 가상 디렉터리에 대해 동일한 이름으로 웹 공유를 설정할 때 - 이미 있다고 오류발생
190정성태12/11/200515032    답변글 VC++: 31.6. ASP.NET 소스세이프 오류현상: 다른 사람이 체크아웃 한 것을 또 다른 사람이 체크아웃 가능!
191정성태12/11/200517438    답변글 VC++: 31.7. 소스 세이프 사용 시, 특정 프로젝트의 빌드 체크가 솔루션 로드할 때마다 해제되는 경우
118정성태3/30/200623184VC++: 14. TCP through HTTP tunneling: 기업 내 Proxy 서버 제한에서 벗어나는 방법 [2]
117정성태3/19/200524257.NET Framework: 30. Process.Start에서의 인자 길이 제한 [4]
116정성태3/14/200516821.NET Framework: 29. [.NET WebService] 자동생성되는 WSDL 을 막는 방법.
115정성태3/13/200517347VS.NET IDE: 25. [IIS 서버] ODBC 로그 남기기 [1]
195정성태12/21/200516629    답변글 VC++: 25.1. ODBC 로그를 못 남길 때의 오류 화면
113정성태3/13/200517435VS.NET IDE: 24. [VPC] 타이머 동기화 기능 제거
110정성태11/14/200516353.NET Framework: 28. VS.NET 2005 / SQL Server 2005 베타 버전 재설치 또는 업그레이드 [1]
111정성태3/7/200515260    답변글 VS.NET IDE: 28.1. [추가] SQL 2005 / VS.NET 2005 2005-02 CTP 버전이 올라왔네요. [1]
112정성태11/14/200516511        답변글 VS.NET IDE: 28.2. [추가] VS.NET 2005 2005-02 CTP 버전에서 달라진 점 ( VC++ )
127정성태3/29/200514541        답변글 VS.NET IDE: 28.4. [추가] SQL 2005 2005-02 CTP 버전에서 달라진 점
... 181  182  183  184  185  186  187  188  189  190  191  [192]  193  194  195  ...