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)
1426정성태3/29/201324000개발 환경 구성: 186. SCOM 2012 환경 구성 - 관리 대상 추가
1424정성태3/21/201325805개발 환경 구성: 185. System Center 2012 Operations Manager 설치
1423정성태3/18/201320847오류 유형: 170. The specified domain either does not exist or could not be contacted.
1422정성태3/14/201323028오류 유형: 169. Windows 8/2012에 .NET 3.5가 설치되지 않는 경우
1421정성태3/13/201340252.NET Framework: 364. WCF RIA 서비스 + Silverlight 사용 예제
1420정성태3/12/201325004오류 유형: 168. ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
1419정성태3/12/201321520Windows: 70. 관리 도구에서 "Windows Server Backup" 항목이 없는 경우
1418정성태2/28/201331418오류 유형: 167. Internet Explorer 10 설치 후 Flash 객체의 메서드/속성 접근 오류가 발생한다면?
1417정성태2/25/201327583.NET Framework: 363. ASP.NET AJAX PageMethods - ASPX.cs의 static 메서드를 AJAX로 호출파일 다운로드1
1416정성태2/22/201330191개발 환경 구성: 184. Xamarin 2.0 - Visual Studio에서 Android 앱을 폰으로 직접 배포하는 방법
1415정성태2/21/201337453개발 환경 구성: 183. Xamarin 2.0 - 윈도우 환경의 Visual Studio에서 C#으로 iOS/Android 응용 프로그램 개발 [4]파일 다운로드1
1414정성태2/21/201332639개발 환경 구성: 182. JMeter로 XML 웹 서비스 호출에 대한 부하 테스트 방법파일 다운로드2
1413정성태2/19/201331975VC++: 66. Chromium 컴파일하는 방법 - 두 번째 이야기 [3]
1412정성태2/6/201333847VC++: 65. Python 소스코드를 Visual C++로 빌드하는 방법 [3]
1411정성태1/31/201349170개발 환경 구성: 181. 무료 데이터베이스 서버 성능 비교(SQL Server Express, IBM DB2 Express, MySQL, Sybase, PostgreSQL, Oracle XE) [9]
1410정성태1/31/201331023.NET Framework: 362. C# - 닷넷 응용 프로그램에서 Sybase DB 사용 [1]파일 다운로드1
1409정성태1/30/201334906.NET Framework: 361. C# - 공유기 관리 웹 페이지 인증 [4]파일 다운로드1
1408정성태1/29/201329800.NET Framework: 360. C# - 닷넷 응용 프로그램에서 DB2 Express-C 데이터베이스 사용 (2) [1]파일 다운로드1
1407정성태1/29/201328202.NET Framework: 359. C# - 닷넷 응용 프로그램에서 DB2 Express-C 데이터베이스 사용 (1)
1406정성태1/22/201322551개발 환경 구성: 180. Windows Server 2012 RC 버전을 RTM으로 업그레이드하는 방법
1405정성태1/16/201344242.NET Framework: 358. C# - 닷넷 응용 프로그램에서 MySQL(MySqlConnector) 사용 [7]파일 다운로드1
1404정성태1/15/201329109개발 환경 구성: 179. Hyper-V VM 복사는 robocopy로. [2]
1403정성태1/14/201331962.NET Framework: 357. .NET 4.5의 2GB 힙 한계 극복
1402정성태1/14/201332473오류 유형: 166. SmtpClient.Send 오류 - net_io_connectionclosed
1401정성태1/11/201329773.NET Framework: 356. (공개키를 담은) 자바의 key 파일을 닷넷의 RSACryptoServiceProvider에서 사용하는 방법 [2]파일 다운로드1
1400정성태1/10/201328953Windows: 69. 작업표시줄의 터치 키보드(Touch Keyboard) 없애는 방법 [3]
... 136  137  138  139  140  141  142  143  144  [145]  146  147  148  149  150  ...