SlideShare ist ein Scribd-Unternehmen logo
1 von 28
HTML5 Graphics
Dave Isbitski
Sr. Developer Evangelist
David.Isbitski@microsoft.com
blogs.msdn.com/davedev
@TheDaveDev
HTML5 and Friends




                                                 via Giorgio Sardo:
     blogs.msdn.com/b/giorgio/archive/2010/10/28/what-is-html5.aspx
HTML



CSS     JavaScript
Cascading Style Sheets (CSS)

CSS 2.1
   Support Widespread

Many New CSS3 Modules
   Backgrounds & Borders
   Color
   Fonts (including WOFF)
   Media Queries
   Namespaces
   Selectors
   Values & Units
   Box Shadow
   2D & 3D Transforms, Transitions
The Power of the Whole PC

     GREETINGS PROFESSOR FALKEN.

      WOULD YOU LIKE TO PLAY A
           GAME OF CHESS?

                 █
IE9 Hardware Acceleration
  A Tale of GPUs and CPUs

GPUs Commonplace
  Text, Video, and Graphics


Multiple Processor Cores
(WEI Mar 2011 = 2.42)

Support for both in
Internet Explorer 9 (and beyond)
Scalable Vector Graphics (SVG)

SVG 1.1
Vector Based
  Use Geometry
XML format
  Familiarity
  Readability
  Accessibility
SVG Graphics
Declarative, XML based, royalty-free format for
describing 2D Vector graphics
Broad Adoption and Tools – released September
4, 2001
Shapes:
  ‘path’, ‘rect’, ‘circle’, ‘ellipse’,
  ‘line’, ‘polyline’ and ‘polygon’
Text
Solid Colors, Linear and Radial Gradients,
Patterns
Styling (inline & CSS)
Retained v. Immediate

Retained mode retains a complete model of
the objects to be rendered
  Example: SVG
Immediate mode directly causes rendering of
graphics objects to the display
  Example: HTML5 Canvas
SVG 101
<svg width="400" height="200"
xmlns="http://www.w3.org/2000/svg">
    <rect fill="red" x="20" y="20" width="100" height="75" />
    <rect fill="blue" x="50" y="50" width="100" height="75" />
</svg>
Advantages of SVG
Static or Dynamic
Preserves Fidelity
  Vectors, High-DPI, Printing, etc.
Declarative syntax (i.e. tooling)
Improved accessibility
  Part of the DOM, Screen Readers
Interactivity through events
Supports embedded content (ie. XML
fragments)
SVG

 Demos
Some SVG Generation Tools
Inkscape
  http://inkscape.org

Adobe Illustrator
  Export to SVG
  BTW: AI -> Canvas
     http://visitmix.com/labs/ai2canvas

Microsoft Visio
  Save as SVG
  http://office.microsoft.com/visio
Some SVG Libraries
 RaphaelJS
   http://raphaeljs.com


 Dojo Toolkit
   http://dojotoolkit.org


 Protovis
   Graphing library
   http://vis.stanford.edu/protovis
HTML5 Canvas
Dynamic, scriptable
rendering of 2D
shapes and bitmaps
Simple API; 45
methods and 21
attributes
Typically hardware-
accelerated
HTML5 Canvas
HTML5 Element
                              U haz an old
  Bitmap Based                  browser
  JavaScript Driven

2D API
  Rectangles, Paths, Lines,
  Fills, Arcs, Curves, etc.

“Immediate Mode”
Colours and
  State       Compositing
                              Styles


                              Simple
Line Styles    Shadows
                              Shapes


 Complex        Focus
                               Text
 Shapes       Management


                       Pixel
          Images
                    Manipulation
Canvas on One Canvas!
state                             Shadows                             text
                                          attribute double                   attribute DOMString font;
    void save();
                                          shadowOffsetX;                     attribute DOMString textAlign;
    void restore();
                                          attribute double                   attribute DOMString textBaseline;
transformations                                                              void fillText(…);
                                          shadowOffsetY;
    void   scale(…);                                                         void strokeText(…);
    void   rotate(…);
                                          attribute double
                                          shadowBlur;                        TextMetrics measureText(…);
    void   translate(…);                                              pixel manipulation
                                          attribute DOMString
    void   transform(…);                                                     ImageData createImageData(…);
                                          shadowColor;
    void   setTransform(…);                                                  ImageData createImageData(…);
                                  Rects
compositing                                                                  ImageData getImageData(…);
                                          void clearRect(…);
    globalAlpha;                                                             void putImageData(…);
                                          void fillRect(…);
    globalCompositeOperation;
                                          void strokeRect(…);         interface CanvasGradient {
colors and styles
                                  path API                                   void addColorStop(…); };
    strokeStyle;
                                          void beginPath();           interface CanvasPattern {};
    fillStyle;
    CanvasGradient                        void closePath();           interface TextMetrics {
    createLinearGradient(…);              void moveTo(…);                    readonly attribute double width;
    CanvasGradient                        void lineTo(…);                    };
    createRadialGradient(…);              void quadraticCurveTo(…);   interface ImageData {
    CanvasPattern                                                            readonly attribute unsigned long
                                          void bezierCurveTo(…);             width;
    createPattern(…);
                                          void arcTo(…);                     readonly attribute unsigned long
Line caps/joins                           void rect(…);                      height;
    attribute double lineWidth;                                              readonly attribute
                                          void arc(…);
    attribute DOMString                                                      CanvasPixelArray data; };
    lineCap;                              void fill();
                                                                      interface CanvasPixelArray {
    attribute DOMString                   void stroke();
                                                                             readonly attribute unsigned long
    lineJoin;                             void clip();                       length;
    attribute double                      boolean isPointInPath(…);          getter octet (…);
    miterLimit;
                                  focus management                           setter void (…); };
                                          boolean drawFocusRing(…);
                                  drawing images
                                          void drawImage(…);
                                                                      Via Jatinder Mann – MIX11
Canvas 101
<canvas id="myCanvas" width="200" height="200">
  No canvas support.
</canvas>

<script type="text/javascript">
  var canvas = document.getElementById("myCanvas");
  var ctx = canvas.getContext("2d");
  ctx.fillStyle = "rgb(255,0,0)";
  ctx.fillRect(30, 30, 50, 50);
</script>
Some Advantages of HTML5 Canvas
 Script-based scene graph
 Programmatic generation of
 images
 Drawing pixels
 Constant performance
HTML5 Canvas

  Demos
Best Practice: Feature Detection
var canvas =
document.createElement(“canvas”);
   if (canvas && canvas.getContext &&
       canvas.getContext(“2d”))
   {
        // Code requiring canvas support
   } else {
        // Canvas isn’t available.
        // Put non-canvas fallback here
   }
A Canvas Library Example

  EaselJS
    http://easeljs.com
svg versus canvas
SVG and Canvas

              Canvas                         SVG

Abstraction   Pixel based                    Shape based

Elements      Single HTML element            Multiple graphical elements
                                             which become part of the DOM

Driver        Script only                    Script and CSS

Event Model   User Interaction is granular   User Interaction is abstracted
              (x,y)                          (rect, path)

Performance   Performance is better with    Performance is better with
              smaller surface and/or larger smaller number of objects
              number of objects             and/or larger surface.

                                                       Via Jatinder Mann - MIX
Scenarios: Canvas and SVG

                    Complex
                 scenes, lots of
Screen Capture       objects
                                                       Static Images
                                     Interactive       (logos, diagrams,
                                   Charts, Graphs            etc.)




                                                       High Fidelity
                                    2D Gaming         Documents for
                                                         Viewing,
                                                         Printing
  Video                    Web
Manipulation            Advertising
                                                    Or… consider both!
Resources
Demos and More
  BeautyOfTheWeb.com
  IETestDrive.com
  msdn.com/ie

SVG & Canvas
  http://msdn.com/gg193983.aspx

Sessions
  live.visitmix.com, buildwindows.com
HTML5 Graphics
Dave Isbitski
Sr. Developer Evangelist
David.Isbitski@microsoft.com
blogs.msdn.com/davedev
@TheDaveDev

Weitere ähnliche Inhalte

Ähnlich wie HTML5 Graphics - Canvas and SVG

How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
Bitla Software
 
Building Windows 8 Metro Style casual games using HTML5 and JavaScript
Building Windows 8 Metro Style casual games using HTML5 and JavaScriptBuilding Windows 8 Metro Style casual games using HTML5 and JavaScript
Building Windows 8 Metro Style casual games using HTML5 and JavaScript
David Isbitski
 
Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and Animation
Mindfire Solutions
 

Ähnlich wie HTML5 Graphics - Canvas and SVG (20)

Intro to HTML5 Canvas
Intro to HTML5 CanvasIntro to HTML5 Canvas
Intro to HTML5 Canvas
 
How to build a html5 websites.v1
How to build a html5 websites.v1How to build a html5 websites.v1
How to build a html5 websites.v1
 
Writing a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 CanvasWriting a Space Shooter with HTML5 Canvas
Writing a Space Shooter with HTML5 Canvas
 
An in-depth look at jQuery
An in-depth look at jQueryAn in-depth look at jQuery
An in-depth look at jQuery
 
Processing presentation
Processing presentationProcessing presentation
Processing presentation
 
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics PerformanceGoogle I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
 
Google I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics PerformanceGoogle I/O 2013 - Android Graphics Performance
Google I/O 2013 - Android Graphics Performance
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5
 
Building Windows 8 Metro Style casual games using HTML5 and JavaScript
Building Windows 8 Metro Style casual games using HTML5 and JavaScriptBuilding Windows 8 Metro Style casual games using HTML5 and JavaScript
Building Windows 8 Metro Style casual games using HTML5 and JavaScript
 
Html5 Canvas Drawing and Animation
Html5 Canvas Drawing and AnimationHtml5 Canvas Drawing and Animation
Html5 Canvas Drawing and Animation
 
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhBuilding Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
 
Mlocjs buzdin
Mlocjs buzdinMlocjs buzdin
Mlocjs buzdin
 
Skia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics EssentialsSkia & Freetype - Android 2D Graphics Essentials
Skia & Freetype - Android 2D Graphics Essentials
 
Bringing your app to the web with Dart - Chris Buckett (Entity Group)
Bringing your app to the web with Dart - Chris Buckett (Entity Group)Bringing your app to the web with Dart - Chris Buckett (Entity Group)
Bringing your app to the web with Dart - Chris Buckett (Entity Group)
 
How to make a video game
How to make a video gameHow to make a video game
How to make a video game
 
Overcoming The Impedance Mismatch Between Source Code And Architecture
Overcoming The Impedance Mismatch Between Source Code And ArchitectureOvercoming The Impedance Mismatch Between Source Code And Architecture
Overcoming The Impedance Mismatch Between Source Code And Architecture
 
SVGD3Angular2React
SVGD3Angular2ReactSVGD3Angular2React
SVGD3Angular2React
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
 
Visualization of Big Data in Web Apps
Visualization of Big Data in Web AppsVisualization of Big Data in Web Apps
Visualization of Big Data in Web Apps
 
Practical Models in Practice
Practical Models in PracticePractical Models in Practice
Practical Models in Practice
 

Mehr von David Isbitski

Screencast dave dev-introtoask-andecho-july2015
Screencast dave dev-introtoask-andecho-july2015Screencast dave dev-introtoask-andecho-july2015
Screencast dave dev-introtoask-andecho-july2015
David Isbitski
 
Playing music and sound effects in a windows 8 metro style app using html5 an...
Playing music and sound effects in a windows 8 metro style app using html5 an...Playing music and sound effects in a windows 8 metro style app using html5 an...
Playing music and sound effects in a windows 8 metro style app using html5 an...
David Isbitski
 

Mehr von David Isbitski (16)

Screencast dave dev-introtoask-andecho-july2015
Screencast dave dev-introtoask-andecho-july2015Screencast dave dev-introtoask-andecho-july2015
Screencast dave dev-introtoask-andecho-july2015
 
Lap Around Azure Build Updates
Lap Around Azure Build UpdatesLap Around Azure Build Updates
Lap Around Azure Build Updates
 
Hosting a WordPress Blog on Azure Websites
Hosting a WordPress Blog on Azure WebsitesHosting a WordPress Blog on Azure Websites
Hosting a WordPress Blog on Azure Websites
 
Azure Mobile Services for iOS
Azure Mobile Services for iOSAzure Mobile Services for iOS
Azure Mobile Services for iOS
 
Building Apps for the new Windows Store
Building Apps for the new Windows Store Building Apps for the new Windows Store
Building Apps for the new Windows Store
 
Windows Phone 8 Sensors
Windows Phone 8 SensorsWindows Phone 8 Sensors
Windows Phone 8 Sensors
 
More Than An App
More Than An AppMore Than An App
More Than An App
 
Designing for Windows Phone 8
Designing for Windows Phone 8Designing for Windows Phone 8
Designing for Windows Phone 8
 
A Developer Lap Around Windows Phone 8
A Developer Lap Around Windows Phone 8 A Developer Lap Around Windows Phone 8
A Developer Lap Around Windows Phone 8
 
Windows Azure Mobile Services
Windows Azure Mobile ServicesWindows Azure Mobile Services
Windows Azure Mobile Services
 
Windows Store Apps with HTML and JavaScript
Windows Store Apps with HTML and JavaScriptWindows Store Apps with HTML and JavaScript
Windows Store Apps with HTML and JavaScript
 
Designing a Windows Store App
Designing a Windows Store AppDesigning a Windows Store App
Designing a Windows Store App
 
Playing music and sound effects in a windows 8 metro style app using html5 an...
Playing music and sound effects in a windows 8 metro style app using html5 an...Playing music and sound effects in a windows 8 metro style app using html5 an...
Playing music and sound effects in a windows 8 metro style app using html5 an...
 
Windows Phone App Development
Windows Phone App DevelopmentWindows Phone App Development
Windows Phone App Development
 
HTML5 Gaming
HTML5 GamingHTML5 Gaming
HTML5 Gaming
 
Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!
Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!
Living the Dream: Make the Video Game You’ve Always Wanted and Get Paid For It!
 

Kürzlich hochgeladen

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

HTML5 Graphics - Canvas and SVG

  • 1. HTML5 Graphics Dave Isbitski Sr. Developer Evangelist David.Isbitski@microsoft.com blogs.msdn.com/davedev @TheDaveDev
  • 2. HTML5 and Friends via Giorgio Sardo: blogs.msdn.com/b/giorgio/archive/2010/10/28/what-is-html5.aspx
  • 3. HTML CSS JavaScript
  • 4. Cascading Style Sheets (CSS) CSS 2.1 Support Widespread Many New CSS3 Modules Backgrounds & Borders Color Fonts (including WOFF) Media Queries Namespaces Selectors Values & Units Box Shadow 2D & 3D Transforms, Transitions
  • 5. The Power of the Whole PC GREETINGS PROFESSOR FALKEN. WOULD YOU LIKE TO PLAY A GAME OF CHESS? █
  • 6. IE9 Hardware Acceleration A Tale of GPUs and CPUs GPUs Commonplace Text, Video, and Graphics Multiple Processor Cores (WEI Mar 2011 = 2.42) Support for both in Internet Explorer 9 (and beyond)
  • 7. Scalable Vector Graphics (SVG) SVG 1.1 Vector Based Use Geometry XML format Familiarity Readability Accessibility
  • 8. SVG Graphics Declarative, XML based, royalty-free format for describing 2D Vector graphics Broad Adoption and Tools – released September 4, 2001 Shapes: ‘path’, ‘rect’, ‘circle’, ‘ellipse’, ‘line’, ‘polyline’ and ‘polygon’ Text Solid Colors, Linear and Radial Gradients, Patterns Styling (inline & CSS)
  • 9. Retained v. Immediate Retained mode retains a complete model of the objects to be rendered Example: SVG Immediate mode directly causes rendering of graphics objects to the display Example: HTML5 Canvas
  • 10. SVG 101 <svg width="400" height="200" xmlns="http://www.w3.org/2000/svg"> <rect fill="red" x="20" y="20" width="100" height="75" /> <rect fill="blue" x="50" y="50" width="100" height="75" /> </svg>
  • 11. Advantages of SVG Static or Dynamic Preserves Fidelity Vectors, High-DPI, Printing, etc. Declarative syntax (i.e. tooling) Improved accessibility Part of the DOM, Screen Readers Interactivity through events Supports embedded content (ie. XML fragments)
  • 13. Some SVG Generation Tools Inkscape http://inkscape.org Adobe Illustrator Export to SVG BTW: AI -> Canvas http://visitmix.com/labs/ai2canvas Microsoft Visio Save as SVG http://office.microsoft.com/visio
  • 14. Some SVG Libraries RaphaelJS http://raphaeljs.com Dojo Toolkit http://dojotoolkit.org Protovis Graphing library http://vis.stanford.edu/protovis
  • 15. HTML5 Canvas Dynamic, scriptable rendering of 2D shapes and bitmaps Simple API; 45 methods and 21 attributes Typically hardware- accelerated
  • 16. HTML5 Canvas HTML5 Element U haz an old Bitmap Based browser JavaScript Driven 2D API Rectangles, Paths, Lines, Fills, Arcs, Curves, etc. “Immediate Mode”
  • 17. Colours and State Compositing Styles Simple Line Styles Shadows Shapes Complex Focus Text Shapes Management Pixel Images Manipulation
  • 18. Canvas on One Canvas! state Shadows text attribute double attribute DOMString font; void save(); shadowOffsetX; attribute DOMString textAlign; void restore(); attribute double attribute DOMString textBaseline; transformations void fillText(…); shadowOffsetY; void scale(…); void strokeText(…); void rotate(…); attribute double shadowBlur; TextMetrics measureText(…); void translate(…); pixel manipulation attribute DOMString void transform(…); ImageData createImageData(…); shadowColor; void setTransform(…); ImageData createImageData(…); Rects compositing ImageData getImageData(…); void clearRect(…); globalAlpha; void putImageData(…); void fillRect(…); globalCompositeOperation; void strokeRect(…); interface CanvasGradient { colors and styles path API void addColorStop(…); }; strokeStyle; void beginPath(); interface CanvasPattern {}; fillStyle; CanvasGradient void closePath(); interface TextMetrics { createLinearGradient(…); void moveTo(…); readonly attribute double width; CanvasGradient void lineTo(…); }; createRadialGradient(…); void quadraticCurveTo(…); interface ImageData { CanvasPattern readonly attribute unsigned long void bezierCurveTo(…); width; createPattern(…); void arcTo(…); readonly attribute unsigned long Line caps/joins void rect(…); height; attribute double lineWidth; readonly attribute void arc(…); attribute DOMString CanvasPixelArray data; }; lineCap; void fill(); interface CanvasPixelArray { attribute DOMString void stroke(); readonly attribute unsigned long lineJoin; void clip(); length; attribute double boolean isPointInPath(…); getter octet (…); miterLimit; focus management setter void (…); }; boolean drawFocusRing(…); drawing images void drawImage(…); Via Jatinder Mann – MIX11
  • 19. Canvas 101 <canvas id="myCanvas" width="200" height="200"> No canvas support. </canvas> <script type="text/javascript"> var canvas = document.getElementById("myCanvas"); var ctx = canvas.getContext("2d"); ctx.fillStyle = "rgb(255,0,0)"; ctx.fillRect(30, 30, 50, 50); </script>
  • 20. Some Advantages of HTML5 Canvas Script-based scene graph Programmatic generation of images Drawing pixels Constant performance
  • 21. HTML5 Canvas Demos
  • 22. Best Practice: Feature Detection var canvas = document.createElement(“canvas”); if (canvas && canvas.getContext && canvas.getContext(“2d”)) { // Code requiring canvas support } else { // Canvas isn’t available. // Put non-canvas fallback here }
  • 23. A Canvas Library Example EaselJS http://easeljs.com
  • 25. SVG and Canvas Canvas SVG Abstraction Pixel based Shape based Elements Single HTML element Multiple graphical elements which become part of the DOM Driver Script only Script and CSS Event Model User Interaction is granular User Interaction is abstracted (x,y) (rect, path) Performance Performance is better with Performance is better with smaller surface and/or larger smaller number of objects number of objects and/or larger surface. Via Jatinder Mann - MIX
  • 26. Scenarios: Canvas and SVG Complex scenes, lots of Screen Capture objects Static Images Interactive (logos, diagrams, Charts, Graphs etc.) High Fidelity 2D Gaming Documents for Viewing, Printing Video Web Manipulation Advertising Or… consider both!
  • 27. Resources Demos and More BeautyOfTheWeb.com IETestDrive.com msdn.com/ie SVG & Canvas http://msdn.com/gg193983.aspx Sessions live.visitmix.com, buildwindows.com
  • 28. HTML5 Graphics Dave Isbitski Sr. Developer Evangelist David.Isbitski@microsoft.com blogs.msdn.com/davedev @TheDaveDev

Hinweis der Redaktion

  1. Z order is whichever is first so red rect is before blue-rect can be inline in html or external resources.
  2. Election Results – High Fidelity: http://ie.microsoft.com/testdrive/Graphics/AtlaszurEuropawahl/Default.xhtml – Zoom in and out. LOB applications, and dynamic.
  3. 2004 – Apple in Webkit. Used to power dashboard widgets and safari browser itself.2006 – general use by folks Now part of HTML5APIs is part of low level drawing API – Immediate mode is very fast performance.
  4. Can incorporate video and even get rgb value of a pixel.
  5. http://ie.microsoft.com/testdrive/Graphics/CanvasPad/Default.htmlRectangles, arcs and then quadratic. Show clipping and talk about interval timer. Then show gradient calls on kite and show shadows. Them image and video (could even do transforms on rgb values of video). Show transforms and animation. ctx.shadowColor = &apos;red&apos;; other timer gradual fades what was visible into background via 0.1.