Canvas plotting of HTML5-image processing tutorial

Source: Internet
Author: User
ArticleDirectory
    • The following is the source code of a specific cropping method:
    • After:

Canvas is a powerful canvas that allows you to write. Of course, it also supports image processing.

Drawimage (image, dx, Dy );// Used for display, sometimes exceeding

Drawimage (image, dx, Dy, DW, DH );// Used for scaling

Drawimage (image, Sx, Sy, SW, sh, dx, Dy, DW, SH );// Used for cropping, scaling, and display

Note: image is an image object. dx is the X coordinate in the canvas, Dy is the Y coordinate in the canvas, DW is the width of the image in the canvas, Dy is the height of the image in the canvas, Sx, sy, SW, and sh are the X, Y, width, and height values in the original image respectively (I'm lazy, just write it ).

The following is a method for tailoring. Source code :
 <!  Doctype html  > <  Html  >   <  Head  >      <  Meta  Charset  = "UTF-8"  >      <  Title  > Canvas </  Title  >  </  Head  >   <  Style  Type  = "Text/CSS"  >  Body  {  Margin  :  20px auto  ; Padding  :  0  ;  Width  :  800px  ;   }  Canvas  {  Border :  Dashed 2px # ccc  }   </  Style  >   <  Script  Type  = "Text/JavaScript"  >      Function  $ (ID ){  Return Document. getelementbyid (ID );}  Function  Pageload (){  VaR  Can  =  $ (  '  Can  '  ); VaR  Cans  =  Can. getcontext (  '  2d  '  );  VaR  Objimg  =   New Image (); objimg. SRC  =   '  Lin.jpg  '  ; Objimg. onload  =   Function  () {Cans. drawimage (objimg,  500  , 400  ,  500  ,  400  ,  100  ,  100  ,  500  , 400  );}}  </  Script  >  <  Body  Onload  = "Pageload ();"  >      <  Canvas  ID  = "Can"  Width  = "800px" Height  = "600px"  Onclick  = "Img_click (this );"  > </  Canvas  >  </  Body  >  </  Html  > 
Original Image -- A pretty girl, hahaha

After:

 

If you have any questions, refer to: http://www.aqee.net/html-5-canvas-tutorial-displaying-images/

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.