380 likes | 623 Views
Best Practices for Creating Advanced Graphics . Leon Braginski Senior Program Manager Microsoft Corporation. Objectives. Learn about advanced graphics techniques in Internet Explorer 9 Understand best practices for creating high performance, graphically rich websites. Agenda.
E N D
Best Practices for Creating Advanced Graphics Leon Braginski Senior Program Manager Microsoft Corporation
Objectives • Learn about advanced graphics techniques in Internet Explorer 9 • Understand best practices for creating high performance, graphically rich websites
Agenda • How Internet Explorer 9 takes advantage of the GPU • Best practices for high performance canvas and SVG • Rich styling by using CSS3 • Best practices for high performance video
GPU-Powered HTML 5 • All HTML5 is GPU-accelerated • Internet Explorer uses DirectX • Direct2D • DirectWrite GPUs GPU Architecture Multi-Core CPU
Basic Technique for Animating Canvas with Images • Render the image on canvas • Clear canvas • Repeat
Best Practice: Drawing an Image Cell • Consider using an image sprite as a high performance approach sY sX fishH fishW
Drawing a Single Image Cell <img id="imageStrip" src="fishstrip.png" style="display: none" tabIndex="-1"> // get image strip imageStrip = document.getElementById('imageStrip'); ctx.drawImage ( // source image information FishImageStrip, // source fishW * cell, // sX of the fish cell fishH * species, // SY of the fish cell fishW, // cell width fishH, // cell height // Canvas Destination x, // X where to draw fish y, // Y where to draw fish on canvas fishW, // destination width fishH, // destination height );
demo Fish Sprite, and Rendering a Fish from Sprite on Canvas
Making it More Interesting: Canvas with Images • Load the background • Load the entire image sprite • Transform canvas (scale, translate) • Render the specific cell from the strip • Repeat steps 3-4
Animating Canvas with Images varmyCanvas= document.getElementById('myCanvas'); varctx = myCanvas.getContext("2d"); … ctx.save(); ctx.translate(x, y); ctx.scale(scale, scale); ctx.transform(flip, 0, 0, 1, 0, 0); ctx.drawImage(imageStrip, fishW * cell, fishH * species, fishW, fishH, -fishW / 2, -fishH / 2, fishW, fishH); ... ctx.restore();
demo Adding Background and Canvas Transforms
demo SVG Simple and Complex Animations
CSS Visual Elements .bottomshade { position: absolute; top: 50%; left: 0; width: 100%; height: 50%; background-color: rgba(0,0,0,0.5); border-radius: 25px; }
Implementing Multiple Backgrounds #demo { background-image: url('backgrounds/crosshair.svg'), url('backgrounds/ufo.svg'), url('backgrounds/clouds.svg'); background-position: 600px 500px, 300px 200px, 0px 0px; background-clip: padding-box, border-box, border-box; background-repeat: no-repeat, no-repeat, repeat; } <div id="demo"></div>
demo Graphically Rich CSS3 Styles and Multiple Backgrounds
Using Rich Fonts • Take advantage of DirectWrite sub-pixel positioning • Use Web Open Font Format (WOFF) fonts
Using Fonts With WOFF Without WOFF <style type="text/css"> #myText { font-family: Gabriola, Georgia, Serif; text-align: center; font-size: 48pt; color: Black; line-height: 1.0em; padding-bottom: 0.3em; letter-spacing: 0em; } </style> <div id=“myText"> Web Font </div> <style type="text/css"> @font-face { font-family: FelbridgeOTSCondensed; src: url('FelbridgeOTS-Condensed.woff'); } #title{ font: 30pt FelbridgeOTSCondensed, sans-serif; letter-spacing: 0.01em; text-align:center; color:white; background-color:rgb(152,155,177); } </style> <div id="title"> WOFF Font </div>
Getting or Creating WOFF Fonts • Convert open source and freeware fonts to WOFF • Read the license to ensure that conversion is allowed • Font conversion utilities and services are available at http://www.fontsquirrel.com/ • License fonts directly from a font vendor • Use font subscription services
WOFF Font Subscription Services • Typekit: http://typekit.com • Ascender: http://ascenderfonts.com • Font Bureau: http://www.fontbureau.com/ • Monotype Imaging: http://fonts.com • Google Fonts API: http://code.google.com/apis/webfonts/
demo Web and WOFF Fonts
Video Encoding • Take advantage of various video encoding tools Microsoft Expression Encoder
Video Encoding • You can use an open source encoder HandBrake
Media Supported in Internet Explorer 9 • All H.264 encoding profiles are supported • Supported video codecs • avc1 (h.264) • vp8 (with appropriate software installed) • Supported audio codecs • MP4A • MP3
Selecting the Encoding Profile • Balance the profile with computing and network needs: • High • Main • Base • High profile ~ 20-30% lower bandwidth usage for about the same quality playback • The baseline profile is a good all-around choice
Video: Using Different Bit Rates • The browser buffers the content to start • Recommended minimum setting: 350Kbps • Recommended maximum setting: 2-3.5 Mbps
Testing for Internet Explorer 9 Codec Support If ( (document.createElement("video"). canPlayType ('video/mp4; codecs="avc1,mp4a"') ) =="probably") { // The H.264 and AAC codecs are supported }
demo Using Video Elements in Internet Explorer 9
Call to Action • Don’t be afraid to use high resolution images • Design for the largest resolution, and let the GPU sample down as needed • Create beautiful graphics • Use alpha channels to create appealing compositions • Use stunning effects, such as rounded borders and shadows • Use rich fonts, including WOFF fonts • Fill out the evaluation form for this presentation
Resources • FakeSMIL: http://leunen.d.free.fr/fakesmile/ • Handbrake for media encoding: http://handbrake.fr/ • Related Windows Summit sessions: • Internet Explorer 9 Overview • Internet Explorer 9 Overview (Update) • Easier Web Development Using Internet Explorer 9 Developer Tools • Internet Explorer 9 Desktop Integration Using Pinning • Getting Started with Canvas • Getting Started with SVG • Touch Support in Internet Explorer 9
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.