[ Team LiB ] • Table of Contents Graphics Programming with GDI+ By Mahesh Chand Publisher: Addison Wesley Pub Date: October 17, 2003 ISBN: 0-321-16077-0 Pages: 784 "This is the most comprehensive book about graphics programming using GDI+ so far. This book will be a very useful handbook for everyone who does graphics programming for Windows." -Min Liu, Software Design Engineer of GDI+, Microsoft Corporation Graphics Programming with GDI+ is the .NET developer's guide to writing graphics applications for Windows and the Web. Through the use of detailed examples it provides experienced programmers with a deep understanding of the entire GDI+ API defined in the .NET Framework class library. The book begins with an introduction to GDI+ and the basics of graphics programming in Windows. The core of the book is a hands-on guide to practical topics, including how to use Windows Forms and optimize GDI+ performance. Chapters demonstrate how to develop real-world tools such as GDI+Painter, GDI+Editor, ImageViewer, and ImageAnimator. The author provides extensive reusable sample code in C# throughout, and complete downloadable source code in C# and Visual Basic .NET is available online, as are color versions of screen shots from the book. Key topics include: How GDI+ compares to GDI How GDI+ is defined and used in the .NET Framework How to draw, paint, and fill graphics objects This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. Viewing and manipulating images Transforming graphics objects, images, and colors Printing in .NET How to develop GDI+ Web applications How to optimize drawing quality and performance Interactive color blending and transparent colors GDI interoperability Answers to frequently asked GDI+ questions Graphics Programming in GDI+ is the most in-depth treatment available on writing effective graphics applications for the .NET Framework. [ Team LiB ] This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. [ Team LiB ] • Table of Contents Graphics Programming with GDI+ By Mahesh Chand Publisher: Addison Wesley Pub Date: October 17, 2003 ISBN: 0-321-16077-0 Pages: 784 Copyright Praise for Graphics Programming with GDI+ Microsoft .NET Development Series Figures Tables Acknowledgments Introduction Who Is This Book For? Prerequisites What's in This Book That I Won't See in Other Books? Chapter Organization Example Source Code Exception and Error Handling in the Samples SUMMARY Chapter 1. GDI+: The Next-Generation Graphics Interface Section 1.1. Understanding GDI+ Section 1.2. Exploring GDI+ Functionality Section 1.3. GDI+ from a GDI Perspective Section 1.4. GDI+ Namespaces and Classes in .NET Summary Chapter 2. Your First GDI+ Application This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. Section 2.1. Drawing Surfaces Section 2.2. The Coordinate System Section 2.3. Tutorial: Your First GDI+ Application Section 2.4. Some Basic GDI+ Objects SUMMARY Chapter 3. The Graphics Class Section 3.1. Graphics Class Properties Section 3.2. Graphics Class Methods Section 3.3. The GDI+Painter Application Section 3.4. Drawing a Pie Chart SUMMARY Chapter 4. Working with Brushes and Pens Section 4.1. Understanding and Using Brushes Section 4.2. Using Pens in GDI+ Section 4.3. Transformation with Pens Section 4.4. Transformation with Brushes Section 4.5. System Pens and System Brushes Section 4.6. A Real-World Example: Adding Colors, Pens, and Brushes to the GDI+Painter Application SUMMARY Chapter 5. Colors, Fonts, and Text Section 5.1. Accessing the Graphics Object Section 5.2. Working with Colors Section 5.3. Working with Fonts Section 5.4. Working with Text and Strings Section 5.5. Rendering Text with Quality and Performance Section 5.6. Advanced Typography Section 5.7. A Simple Text Editor Section 5.8. Transforming Text SUMMARY Chapter 6. Rectangles and Regions Section 6.1. The Rectangle Structure Section 6.2. The Region Class Section 6.3. Regions and Clipping Section 6.4. Clipping Regions Example Section 6.5. Regions, Nonrectangular Forms, and Controls SUMMARY Chapter 7. Working with Images Section 7.1. Raster and Vector Images Section 7.2. Working with Images Section 7.3. Manipulating Images Section 7.4. Playing Animations in GDI+ Section 7.5. Working with Bitmaps Section 7.6. Working with Icons Section 7.7. Skewing Images Section 7.8. Drawing Transparent Graphics Objects This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. Section 7.9. Viewing Multiple Images Section 7.10. Using a Picture Box to View Images Section 7.11. Saving Images with Different Sizes SUMMARY Chapter 8. Advanced Imaging Section 8.1. Rendering Partial Bitmaps Section 8.2. Working with Metafiles Section 8.3. Color Mapping Using Color Objects Section 8.4. Image Attributes and the ImageAttributes Class Section 8.5. Encoder Parameters and Image Formats SUMMARY Chapter 9. Advanced 2D Graphics Section 9.1. Line Caps and Line Styles Section 9.2. Understanding and Using Graphics Paths Section 9.3. Graphics Containers Section 9.4. Reading Metadata of Images Section 9.5. Blending Explained Section 9.6. Alpha Blending Section 9.7. Miscellaneous Advanced 2D Topics SUMMARY Chapter 10. Transformation Section 10.1. Coordinate Systems Section 10.2. Transformation Types Section 10.3. The Matrix Class and Transformation Section 10.4. The Graphics Class and Transformation Section 10.5. Global, Local, and Composite Transformations Section 10.6. Image Transformation Section 10.7. Color Transformation and the Color Matrix Section 10.8. Matrix Operations in Image Processing Section 10.9. Text Transformation Section 10.10. The Significance of Transformation Order SUMMARY Chapter 11. Printing Section 11.1. A Brief History of Printing with Microsoft Windows Section 11.2. Overview of the Printing Process Section 11.3. Your First Printing Application Section 11.4. Printer Settings Section 11.5. The PrintDocument and Print Events Section 11.6. Printing Text Section 11.7. Printing Graphics Section 11.8. Print Dialogs Section 11.9. Customizing Page Settings Section 11.10. Printing Multiple Pages Section 11.11. Marginal Printing: A Caution Section 11.12. Getting into the Details: Custom Controlling and the Print Controller This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. SUMMARY Chapter 12. Developing GDI+ Web Applications Section 12.1. Creating Your First ASP.NET Web Application Section 12.2. Your First Graphics Web Application Section 12.3. Drawing Simple Graphics Section 12.4. Drawing Images on the Web Section 12.5. Drawing a Line Chart Section 12.6. Drawing a Pie Chart SUMMARY Chapter 13. GDI+ Best Practices and Performance Techniques Section 13.1. Understanding the Rendering Process Section 13.2. Double Buffering and Flicker-Free Drawing Section 13.3. Understanding the SetStyle Method Section 13.4. The Quality and Performance of Drawing SUMMARY Chapter 14. GDI Interoperability Section 14.1. Using GDI in the Managed Environment Section 14.2. Cautions for Using GDI in Managed Code SUMMARY Chapter 15. Miscellaneous GDI+ Examples Section 15.1. Designing Interactive GUI Applications Section 15.2. Drawing Shaped Forms and Windows Controls Section 15.3. Adding Copyright Information to a Drawn Image Section 15.4. Reading and Writing Images to and from a Stream or Database Section 15.5. Creating Owner-Drawn List Controls SUMMARY Appendix A. Exception Handling in .NET Section A.1. Why Exception Handling? Section A.2. Understanding the try catch Block Section A.3. Understanding Exception Classes SUMMARY [ Team LiB ] This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. [ Team LiB ] Copyright Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Addison-Wesley was aware of a trademark claim, the designations have been printed with initial capital letters or in all capitals. The .NET logo is either a registered trademark or trademark of Microsoft Corporation in the United States and/or other countries and is used under license from Microsoft. The author and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein. The publisher offers discounts on this book when ordered in quantity for bulk purchases and special sales. For more information, please contact: U.S. Corporate and Government Sales (800) 382-3419 corpsales@pearsontechgroup.com For sales outside of the U.S., please contact: International Sales (317) 581-3793 international@pearsontechgroup.com Visit Addison-Wesley on the Web: www.awprofessional.com Library of Congress Cataloging-in-Publication Data Chand, Mahesh Graphics programming with GDI+ / Mahesh Chand. p. cm. ISBN 0-321-16077-0 (alk. paper) 1. Computer graphics. 2. User interfaces (Computer systems) I. Title T385.C4515 2003 006.6—dc22 2003057705 Copyright © 2004 by Pearson Education, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior consent of the publisher. Printed in the United States of America. Published simultaneously in Canada. For information on obtaining permission for use of material from this work, please submit a written request to: This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. Pearson Education, Inc. Rights and Contracts Department 75 Arlington Street, Suite 300 Boston, MA 02116 Fax: (617) 848-7047 Text printed on recycled paper 1 2 3 4 5 6 7 8 9 10—CRS—0706050403 First printing, October 2003 Dedication To Mel and Neel [ Team LiB ] This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. [ Team LiB ] Praise for Graphics Programming with GDI+ "This is the most comprehensive book about graphics programming using GDI+ so far. A lot of useful sample code inside this book reveals that Mr. Chand apparently has done a fair amount of research on GDI+. This book will be a very useful handbook for everyone who does graphics programming for Windows." —Min Liu, Software Design Engineer of GDI+, Microsoft Corporation "Graphics Programming with GDI+ explores and exploits a wonderful range of GDI+ programming concepts, techniques, and applications for programmers of beginner to intermediate abilities. Being a prolific contributor to the Internet community of developers, Mahesh Chand is offering what seems to be a natural extension of what he does best—sharing his programming skills with other talented programmers. Each chapter compels to the next." —Jason Hattingh, Director, Greystone Digital FX "Mahesh does a very good job getting .NET developers up to speed using the GDI+ features supported in the .NET Framework. There is good coverage of graphics fundamentals that helps the reader better understand the concepts of graphics programming with GDI+, and there are some excellent sample applications that demonstrate the graphics topics covered to reinforce the concepts presented." —Charles G. Parker, President, Parallel Consulting, Inc. "Graphics Programming with GDI+ is a comprehensive reference for anyone who wants to leverage this technology. It presents a clear discussion of the topics in such a manner that is comprehensible to the beginner, but sufficiently in-depth to challenge seasoned programmers." —Deborah J. Bechtold, MCSD, MCDBA [ Team LiB ] This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. [ Team LiB ] Microsoft .NET Development Series John Montgomery, Series Advisor Don Box, Series Advisor Martin Heller, Series Editor The Microsoft .NET Development Series is supported and developed by the leaders and experts of Microsoft development technologies including Microsoft architects and DevelopMentor instructors. The books in this series provide a core resource of information and understanding every developer needs in order to write effective applications and managed code. Learn from the leaders how to maximize your use of the .NET Framework and its programming languages. Titles in the Series Keith Ballinger, .NET Web Services: Architecture and Implementation, 0-321-11359-4 Don Box with Chris Sells, Essential .NET Volume 1: The Common Language Runtime, 0-201-73411-7 Mahesh Chand, Graphics Programming with GDI+, 0-321-16077-0 Anders Hejlsberg, Scott Wiltamuth, Peter Golde, C# Language Specification, 0-321-15491-6 Alex Homer, Dave Sussman, Mark Fussell, A First Look at ADO.NET and System.Xml v. 2.0, 0-321-22839-1 Alex Homer, Dave Sussman, Rob Howard, A First Look at ASP.NET v. 2.0, 0-321-22896-0 Microsoft Common Language Runtime Team, The Common Language Runtime Annotated Reference and Specification, 0-321-15493-2 Microsoft .NET Framework Class Libraries Team, The .NET Framework CLI Standard Class Library Annotated Reference, 0-321-15489-4 Microsoft Visual C# Development Team, The C# Annotated Reference and Specification, 0-321-15491-6 James S. Miller and Susann Ragsdale, The Common Language Infrastructure Annotated Standard, 0-321-15493-2 Fritz Onion, Essential ASP.NET with Examples in C#, 0-201-76040-1 Fritz Onion, Essential ASP.NET with Examples in Visual Basic .NET, 0-201-76039-8 Ted Pattison and Dr. Joe Hummel, Building Applications and Components with Visual Basic .NET, 0-201-73495-8 Chris Sells and Justin Gehtland, Windows Forms Programming in Visual Basic .NET, 0-321-12519-3 Chris Sells, Windows Forms Programming in C#, 0-321-11620-8 Damien Watkins, Mark Hammond, Brad Abrams, Programming in the .NET Environment, 0-201-77018-0 Shawn Wildermuth, Pragmatic ADO.NET: Data Access for the Internet World, 0-201-74568-2 www.awprofessional.com/msdotnetseries/ [ Team LiB ] This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it. Thanks. [...]... This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it Thanks Figure 11 .12 : Figure 11 .13 : Figure 11 .14 : Figure 11 .15 : Figure 11 .16 : Figure 11 .17 : Figure 11 .18 : Figure 11 .19 : Figure 11 .20: Figure 11 . 21: Figure 11 .22: Figure 11 .23: Figure 11 .24: Figure 11 .25: Figure 11 .26: Figure 11 .27: [*] The form with text file printing options 558 [*] A graphics-printing... pixel width 4 81 [*] Combining page and device coordinates 482 [*] Drawing a line and filling a rectangle 487 [*] Rotating graphics objects 488 Figure 10 .10 : Figure 10 .11 : Figure 10 .12 : Figure 10 .13 : Figure 10 .14 : Figure 10 .15 : Figure 10 .16 : Figure 10 .17 : Figure 10 .18 : Figure 10 .19 : [*] Using the RotateAt method 490 [*] Resetting a transformation 490 [*] Scaling a rectangle 492 [*] Shearing a rectangle 493... 11 .3: Conceptual flow of the printing process 530 Figure 11 .4: A flowchart of the printing process 532 Figure 11 .5: Process A 533 Figure 11 .6: Figure 11 .7: Figure 11 .8: Figure 11 .9: [*] Creating a Windows application 534 [*] Your first printing application 535 [*] The printer settings form 547 [*] Reading printer properties 5 51 Figure 11 .10 : Figure 11 .11 : Print events 553 [*] The print events application... Image control 614 [*] Drawing simple graphics objects on the Web 617 Figure 12 .10 : Figure 12 .11 : Figure 12 .12 : Figure 12 .13 : Figure 12 .14 : Figure 12 .15 : Figure 12 .16 : Figure 12 .17 : Figure 12 .18 : [*] Drawing various graphics objects 6 21 [*] Drawing an image 623 [*] Using LinearGradientBrush and PathGradientBrush 625 [*] Drawing semitransparent objects 626 [*] Entering points on a chart 630 [*] A line chart... pie chart–drawing application in ASP.NET 633 [*] The Draw Chart button click in action 636 [*] The Fill Chart button click in action 637 Figure 13 .1: Figure 13 .2: Figure 13 .3: Figure 13 .4: Figure 13 .5: Figure 13 .6: Figure 13 .7: Figure 15 .1: Figure 15 .2: Figure 15 .3: Figure 15 .4: Figure 15 .5: Figure 15 .6: Figure 15 .7: The Form class hierarchy 6 41 [*] Drawing on a form 643 [*] Drawing on Windows controls... intensities 506 Figure 10 .23: A color matrix with multiplication and addition 506 Figure 10 .24: Figure 10 .25: Figure 10 .26: [*] Translating colors 509 [*] Scaling colors 511 [*] Shearing colors 512 Figure 10 .27: RGB rotation space 513 Figure 10 .28: RGB initialization 514 Figure 10 .29: Figure 10 .30: Figure 10 . 31: Figure 10 .32: Figure 10 .33: Figure 10 .34: Figure 10 .35: [*] Rotating colors 515 [*] Using the... style with different colors 14 6 [*] The DiagonalCross style 14 7 [*] The texture brush application 14 8 [*] Using texture brushes 15 1 Figure 4 .10 : Figure 4 .11 : Figure 4 .12 : Figure 4 .13 : Figure 4 .14 : Figure 4 .15 : Figure 4 .16 : Figure 4 .17 : Figure 4 .18 : Figure 4 .19 : [*] Clamping a texture 15 1 [*] The TileFlipY texture option 15 2 [*] A color gradient 15 3 [*] A gradient pattern with pattern repetition 15 3 [*]... 570 Table 11 .8: PageSetupDialog properties 5 71 Table 11 .9: Some PrintPreviewDialog properties 573 Table 11 .10 : PageSettings properties 582 Table 11 .11 : PaperSourceKind members 583 Table 11 .12 : PrintRange members 590 Table 13 .1: ControlStyle members 652 Table 14 .1: DllImportAttribute field members 665 Table 14 .2: CallingConvention members 666 Table 15 .1: DrawItemEventArgs properties 695 Table 15 .2: MeasureItemEventArgs... the Graphics class 495 Table 11 .1: Duplex members 540 This document was created by an unregistered ChmMagic, please go to http://www.bisenter.com to register it Thanks Table 11 .2: Other PrinterSettings properties 543 Table 11 .3: PrinterResolutionKind members 545 Table 11 .4: PrintDocument properties 5 51 Table 11 .5: PrintDocument methods 552 Table 11 .6: PrintPageEventArgs properties 554 Table 11 .7: PrintDialog... 7 .10 : Figure 7 .11 : Figure 7 .12 : Figure 7 .13 : Figure 7 .14 : Figure 7 .15 : Figure 7 .16 : Figure 7 .17 : Figure 7 .18 : Figure 7 .19 : Figure 7.20: Figure 7. 21: [*] An image with default settings 310 [*] The image of Figure 7 .10 , rotated 90 degrees 310 [*] The image of Figure 7 .10 , rotated 18 0 degrees 311 [*] The image of Figure 7 .10 , rotated 270 degrees 311 [*] The image of Figure 7 .10 , flipped in the x direction . Section 11 .4. Printer Settings Section 11 .5. The PrintDocument and Print Events Section 11 .6. Printing Text Section 11 .7. Printing Graphics Section 11 .8. Print Dialogs Section 11 .9 Customizing Page Settings Section 11 .10 . Printing Multiple Pages Section 11 .11 . Marginal Printing: A Caution Section 11 .12 . Getting into the Details: Custom Controlling and the Print Controller This. pie chart–drawing application 12 8 Figure 3.44:The Draw Chart button click in action 13 0 Figure 3.45:The Fill Chart button click in action 13 1 Figure 4 .1: Classes inherited from the Brush class 13 5 Figure