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

비밀번호

댓글 작성자
 




... 136  137  138  139  140  141  142  143  144  145  146  [147]  148  149  150  ...
NoWriterDateCnt.TitleFile(s)
1375정성태11/15/201225931디버깅 기술: 50. windbg의 mscordacwks DLL 로드 문제 - 두 번째 이야기
1374정성태11/13/201223984개발 환경 구성: 175. Visual Studio의 "Extension Manager"에서 설치된 구성 요소들의 제거 버튼이 비활성화되었다면!
1373정성태11/13/201224545.NET Framework: 343. VB.NET 어셈블리의 .NET Reflector 소스 코드를 분석할 때 알아두면 좋은 사항
1372정성태11/1/2012119390Windows: 67. 64비트 윈도우에서 Internet Explorer 10이 항상 64비트로만 실행된다면? [57]
1371정성태10/31/201226971.NET Framework: 342. Python의 zip과 with 문 context를 C#과 비교하면. [3]파일 다운로드1
1370정성태10/31/201222299VS.NET IDE: 75. Visual Studio - "Active Solution Platform" 변경을 툴바에서 하는 방법
1369정성태10/31/201235639개발 환경 구성: 174. 윈도우에서 Mono 개발 환경 구성 [4]
1368정성태10/31/201226902개발 환경 구성: 173. Windows Phone SDK 8.0 설치
1367정성태10/30/201234702개발 환경 구성: 172. IIS 7.5부터 지원되는 웹 사이트 자동 시작 모드 [1]
1366정성태10/24/201225992개발 환경 구성: 171. GTK+를 윈도우 환경에 수작업 설치
1365정성태10/24/201224876개발 환경 구성: 170. 우분투 데스크톱 Active Directory 가입하기 [2]
1364정성태10/19/201221259Windows: 66. Hyper-V 2012에서 별도의 네트워크 카드를 이용한 Live Migration
1363정성태10/16/201228712개발 환경 구성: 169. Objective-C의 대안 - Xamarin의 Mono를 이용한 C# iOS 개발 환경 [2]
1362정성태10/16/201229026개발 환경 구성: 168. 우분투 서버 Active Directory 가입하기
1361정성태10/12/201222469.NET Framework: 341. .NET COM+ 를 Managed/Native 클라이언트에서 각각 호출했을 때의 콜 스택 비교 [4]파일 다운로드1
1360정성태10/9/201226818.NET Framework: 340. Windows Server 2012 - .NET Framework 1.x 미지원
1359정성태10/9/201263099Windows: 65. 윈도우 8 - Internet Explorer 10을 32비트 또는 64비트로 통합 [5]
1358정성태9/27/201226247.NET Framework: 339. .NET Profiler 주의 사항 - 하나의 exe 프로세스 내에 다중 .NET 런타임 사용
1357정성태9/27/201223392Windows: 64. Hyper-V - Windows XP의 Live Migration 오류
1356정성태9/26/201229486Windows: 63. 윈도우 서버 2012 - Hyper-V의 새로운 기능 Live Migration [6]
1355정성태9/21/201227477Team Foundation Server: 49. TFS 2012 Express의 필수 보완 작업: 데이터베이스 백업 [1]
1354정성태9/19/201224292.NET Framework: 338. .NET CLR GC 시간 측정하는 방법파일 다운로드1
1353정성태9/17/201225596.NET Framework: 337. Python의 생성기와 코루틴을 C#으로 표현하면. [2]파일 다운로드1
1352정성태9/13/201223681.NET Framework: 336. .NET Profiler가 COM 개체일까?
1351정성태9/13/201228090디버깅 기술: 49. windbg - .NET Framework 스레드 개체의 COM Apartment 유형 확인하는 방법
1350정성태9/12/201228766개발 환경 구성: 167. (실은) 무료가 아니었던 AWS EC2 서비스 [4]
... 136  137  138  139  140  141  142  143  144  145  146  [147]  148  149  150  ...