Section 25.22. CanvasRenderingContext2D.drawImage( ): draw an image


25.22. CanvasRenderingContext2D.drawImage( ): draw an image

25.22.1. Synopsis

 void drawImage(Image image, float x, float y) void drawImage(Image image, float x, float y,                float width, float height) void drawImage(Image image, integer sourceX, integer sourceY,                integer sourceWidth, integer sourceHeight,                float destX, float destY,                float destWidth, float destHeight) 

25.22.1.1. Arguments

image

The image to be drawn. This must be an Image object representing an <img> tag, or an offscreen image or a Canvas object.


x, y

The point at which the upper-left corner of the image is drawn.


width, height

The size at which the image should be drawn. Specifying these arguments causes the image to be scaled.


sourceX, sourceY

The upper-left corner of the region of the image that is to be drawn. These integer arguments are measured in image pixels.


sourceWidth, sourceHeight

The dimensions, in image pixels, of the region of the image that is to be drawn.


destX, destY

The canvas coordinates at which the upper-left corner of the image region is to be drawn


destWidth, destHeight

The canvas dimensions at which the image region should be drawn.

25.22.2. Description

There are three variants of this method. The first copies the entire image to the canvas, placing its upper-left corner at the specified point and mapping each image pixel to one unit in the canvas coordinate system. The second variant also copies the entire image to the canvas but allows you to specify the desired width and height of the image in canvas units. The third variant is fully general: it allows you to specify any rectangular region of the image and copy it, with arbitrary scaling to any position within the canvas.

The images passed to this method must be Image or Canvas objects. An Image object may represent an <img> tag in the document or an offscreen image created with the Image( ) constructor.

25.22.3. See Also

Image




JavaScript. The Definitive Guide
JavaScript: The Definitive Guide
ISBN: 0596101996
EAN: 2147483647
Year: 2004
Pages: 767

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net