libraries/EaselJS_docs/files/easeljs_display_Bitmap.js.html (view raw)
1<!DOCTYPE html>
2<html lang="en">
3<head>
4 <meta charset="utf-8">
5 <link rel="stylesheet" href="../assets/css/yui-cssgrids-min.css">
6 <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
7 <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
8 <link rel="shortcut icon" type="image/x-icon" href="../assets/favicon.ico">
9 <script src="../assets/js/yui-source.js"></script>
10 <title>EaselJS v1.0.0 API Documentation : easeljs/display/Bitmap.js</title>
11</head>
12<body class="yui3-skin-sam">
13
14<div id="doc">
15 <div id="hd" class="yui3-g header">
16 <div class="yui3-u-3-4">
17
18 <h1><a href="http://www.createjs.com/easeljs"><img src="../assets/docs-icon-EaselJS.png" title="EaselJS"></a></h1>
19
20 </div>
21 <div class="version">
22 <em>API Documentation for: 1.0.0</em>
23 </div>
24 </div>
25 <div id="bd" class="yui3-g">
26
27 <div class="yui3-u-1-4">
28 <div id="docs-sidebar" class="sidebar apidocs">
29 <div id="api-list">
30 <h2 class="off-left">APIs</h2>
31 <div id="api-tabview" class="tabview">
32 <ul class="tabs">
33 <li><a href="#api-classes">Classes</a></li>
34 </ul>
35
36 <div id="api-tabview-filter">
37 <input type="search" id="api-filter" placeholder="Type to filter APIs">
38 </div>
39
40 <div id="api-tabview-panel">
41 <ul id="api-classes" class="apis classes">
42
43 <li><a href="../classes/AlphaMapFilter.html">AlphaMapFilter</a></li>
44
45 <li><a href="../classes/AlphaMaskFilter.html">AlphaMaskFilter</a></li>
46
47 <li><a href="../classes/Bitmap.html">Bitmap</a></li>
48
49 <li><a href="../classes/BitmapCache.html">BitmapCache</a></li>
50
51 <li><a href="../classes/BitmapText.html">BitmapText</a></li>
52
53 <li><a href="../classes/BlurFilter.html">BlurFilter</a></li>
54
55 <li><a href="../classes/ButtonHelper.html">ButtonHelper</a></li>
56
57 <li><a href="../classes/ColorFilter.html">ColorFilter</a></li>
58
59 <li><a href="../classes/ColorMatrix.html">ColorMatrix</a></li>
60
61 <li><a href="../classes/ColorMatrixFilter.html">ColorMatrixFilter</a></li>
62
63 <li><a href="../classes/Container.html">Container</a></li>
64
65 <li><a href="../classes/DisplayObject.html">DisplayObject</a></li>
66
67 <li><a href="../classes/DisplayProps.html">DisplayProps</a></li>
68
69 <li><a href="../classes/DOMElement.html">DOMElement</a></li>
70
71 <li><a href="../classes/EaselJS.html">EaselJS</a></li>
72
73 <li><a href="../classes/Event.html">Event</a></li>
74
75 <li><a href="../classes/EventDispatcher.html">EventDispatcher</a></li>
76
77 <li><a href="../classes/Filter.html">Filter</a></li>
78
79 <li><a href="../classes/Graphics.html">Graphics</a></li>
80
81 <li><a href="../classes/Graphics.Arc.html">Graphics.Arc</a></li>
82
83 <li><a href="../classes/Graphics.ArcTo.html">Graphics.ArcTo</a></li>
84
85 <li><a href="../classes/Graphics.BeginPath.html">Graphics.BeginPath</a></li>
86
87 <li><a href="../classes/Graphics.BezierCurveTo.html">Graphics.BezierCurveTo</a></li>
88
89 <li><a href="../classes/Graphics.Circle.html">Graphics.Circle</a></li>
90
91 <li><a href="../classes/Graphics.ClosePath.html">Graphics.ClosePath</a></li>
92
93 <li><a href="../classes/Graphics.Ellipse.html">Graphics.Ellipse</a></li>
94
95 <li><a href="../classes/Graphics.Fill.html">Graphics.Fill</a></li>
96
97 <li><a href="../classes/Graphics.LineTo.html">Graphics.LineTo</a></li>
98
99 <li><a href="../classes/Graphics.MoveTo.html">Graphics.MoveTo</a></li>
100
101 <li><a href="../classes/Graphics.PolyStar.html">Graphics.PolyStar</a></li>
102
103 <li><a href="../classes/Graphics.QuadraticCurveTo.html">Graphics.QuadraticCurveTo</a></li>
104
105 <li><a href="../classes/Graphics.Rect.html">Graphics.Rect</a></li>
106
107 <li><a href="../classes/Graphics.RoundRect.html">Graphics.RoundRect</a></li>
108
109 <li><a href="../classes/Graphics.Stroke.html">Graphics.Stroke</a></li>
110
111 <li><a href="../classes/Graphics.StrokeDash.html">Graphics.StrokeDash</a></li>
112
113 <li><a href="../classes/Graphics.StrokeStyle.html">Graphics.StrokeStyle</a></li>
114
115 <li><a href="../classes/Matrix2D.html">Matrix2D</a></li>
116
117 <li><a href="../classes/MouseEvent.html">MouseEvent</a></li>
118
119 <li><a href="../classes/MovieClip.html">MovieClip</a></li>
120
121 <li><a href="../classes/MovieClipPlugin.html">MovieClipPlugin</a></li>
122
123 <li><a href="../classes/Point.html">Point</a></li>
124
125 <li><a href="../classes/Rectangle.html">Rectangle</a></li>
126
127 <li><a href="../classes/Shadow.html">Shadow</a></li>
128
129 <li><a href="../classes/Shape.html">Shape</a></li>
130
131 <li><a href="../classes/Sprite.html">Sprite</a></li>
132
133 <li><a href="../classes/SpriteSheet.html">SpriteSheet</a></li>
134
135 <li><a href="../classes/SpriteSheetBuilder.html">SpriteSheetBuilder</a></li>
136
137 <li><a href="../classes/SpriteSheetUtils.html">SpriteSheetUtils</a></li>
138
139 <li><a href="../classes/Stage.html">Stage</a></li>
140
141 <li><a href="../classes/StageGL.html">StageGL</a></li>
142
143 <li><a href="../classes/Text.html">Text</a></li>
144
145 <li><a href="../classes/Ticker.html">Ticker</a></li>
146
147 <li><a href="../classes/Touch.html">Touch</a></li>
148
149 <li><a href="../classes/UID.html">UID</a></li>
150
151 <li><a href="../classes/Utility Methods.html">Utility Methods</a></li>
152
153 <li><a href="../classes/VideoBuffer.html">VideoBuffer</a></li>
154
155 <li><a href="../classes/WebGLInspector.html">WebGLInspector</a></li>
156
157 </ul>
158
159 <ul id="api-modules" class="apis modules">
160
161 <li><a href="../modules/CreateJS.html">CreateJS</a></li>
162
163 <li><a href="../modules/EaselJS.html">EaselJS</a></li>
164
165 </ul>
166 </div>
167 </div>
168</div>
169
170 </div>
171 </div>
172 <div class="yui3-u-3-4">
173 <div id="api-options">
174 Show:
175 <label for="api-show-inherited">
176 <input type="checkbox" id="api-show-inherited" checked>
177 Inherited
178 </label>
179
180 <label for="api-show-protected">
181 <input type="checkbox" id="api-show-protected">
182 Protected
183 </label>
184
185 <label for="api-show-private">
186 <input type="checkbox" id="api-show-private">
187 Private
188 </label>
189 <label for="api-show-deprecated">
190 <input type="checkbox" id="api-show-deprecated">
191 Deprecated
192 </label>
193
194 </div>
195 <div class="apidocs">
196 <div id="docs-main">
197 <div class="content source-content">
198 <script>
199 var name = easeljs/display/Bitmap.js
200</script>
201<h1 class="file-heading">File:Bitmap.js</h1>
202
203<div class="file">
204 <pre class="code prettyprint linenums">
205/*
206* Bitmap
207* Visit http://createjs.com/ for documentation, updates and examples.
208*
209* Copyright (c) 2010 gskinner.com, inc.
210*
211* Permission is hereby granted, free of charge, to any person
212* obtaining a copy of this software and associated documentation
213* files (the "Software"), to deal in the Software without
214* restriction, including without limitation the rights to use,
215* copy, modify, merge, publish, distribute, sublicense, and/or sell
216* copies of the Software, and to permit persons to whom the
217* Software is furnished to do so, subject to the following
218* conditions:
219*
220* The above copyright notice and this permission notice shall be
221* included in all copies or substantial portions of the Software.
222*
223* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
224* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
225* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
226* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
227* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
228* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
229* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
230* OTHER DEALINGS IN THE SOFTWARE.
231*/
232
233/**
234* @module EaselJS
235*/
236
237// namespace:
238this.createjs = this.createjs||{};
239
240(function() {
241
242 /**
243 * A Bitmap represents an Image, Canvas, or Video in the display list. A Bitmap can be instantiated using an existing
244 * HTML element, or a string.
245 *
246 * <h4>Example</h4>
247 *
248 * var bitmap = new createjs.Bitmap("imagePath.jpg");
249 *
250 * <strong>Notes:</strong>
251 * <ol>
252 * <li>When using a video source that may loop or seek, use a {{#crossLink "VideoBuffer"}}{{/crossLink}} object to
253 * prevent blinking / flashing.
254 * <li>When a string path or image tag that is not yet loaded is used, the stage may need to be redrawn before it
255 * will be displayed.</li>
256 * <li>Bitmaps with an SVG source currently will not respect an alpha value other than 0 or 1. To get around this,
257 * the Bitmap can be cached.</li>
258 * <li>Bitmaps with an SVG source will taint the canvas with cross-origin data, which prevents interactivity. This
259 * happens in all browsers except recent Firefox builds.</li>
260 * <li>Images loaded cross-origin will throw cross-origin security errors when interacted with using a mouse, using
261 * methods such as `getObjectUnderPoint`, or using filters, or caching. You can get around this by setting
262 * `crossOrigin` flags on your images before passing them to EaselJS, eg: `img.crossOrigin="Anonymous";`</li>
263 * </ol>
264 *
265 * @class Bitmap
266 * @extends DisplayObject
267 * @constructor
268 * @param {CanvasImageSource | String | Object} imageOrUri The source image to display. This can be a CanvasImageSource
269 * (image, video, canvas), an object with a `getImage` method that returns a CanvasImageSource, or a string URL to an image.
270 * If the latter, a new Image instance with the URL as its src will be used.
271 **/
272 function Bitmap(imageOrUri) {
273 this.DisplayObject_constructor();
274
275
276 // public properties:
277 /**
278 * The source image to display. This can be a CanvasImageSource
279 * (image, video, canvas), an object with a `getImage` method that returns a CanvasImageSource, or a string URL to an image.
280 * If the latter, a new Image instance with the URL as its src will be used.
281 * @property image
282 * @type CanvasImageSource | Object
283 **/
284 if (typeof imageOrUri == "string") {
285 this.image = document.createElement("img");
286 this.image.src = imageOrUri;
287 } else {
288 this.image = imageOrUri;
289 }
290
291 /**
292 * Specifies an area of the source image to draw. If omitted, the whole image will be drawn.
293 * Notes:
294 * <ul>
295 * <li>that video sources must have a width / height set to work correctly with `sourceRect`</li>
296 * <li>Cached objects will ignore the `sourceRect` property</li>
297 * </ul>
298 * @property sourceRect
299 * @type Rectangle
300 * @default null
301 */
302 this.sourceRect = null;
303
304 // private properties:
305 /**
306 * Docced in superclass.
307 */
308 this._webGLRenderStyle = createjs.DisplayObject._StageGL_BITMAP;
309 }
310 var p = createjs.extend(Bitmap, createjs.DisplayObject);
311
312
313// public methods:
314 /**
315 * Constructor alias for backwards compatibility. This method will be removed in future versions.
316 * Subclasses should be updated to use {{#crossLink "Utility Methods/extends"}}{{/crossLink}}.
317 * @method initialize
318 * @deprecated in favour of `createjs.promote()`
319 **/
320 p.initialize = Bitmap; // TODO: deprecated.
321
322 /**
323 * Returns true or false indicating whether the display object would be visible if drawn to a canvas.
324 * This does not account for whether it would be visible within the boundaries of the stage.
325 *
326 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
327 * @method isVisible
328 * @return {Boolean} Boolean indicating whether the display object would be visible if drawn to a canvas
329 **/
330 p.isVisible = function() {
331 var image = this.image;
332 var hasContent = this.cacheCanvas || (image && (image.naturalWidth || image.getContext || image.readyState >= 2));
333 return !!(this.visible && this.alpha > 0 && this.scaleX != 0 && this.scaleY != 0 && hasContent);
334 };
335
336 /**
337 * Draws the display object into the specified context ignoring its visible, alpha, shadow, and transform.
338 * Returns true if the draw was handled (useful for overriding functionality).
339 *
340 * NOTE: This method is mainly for internal use, though it may be useful for advanced uses.
341 * @method draw
342 * @param {CanvasRenderingContext2D} ctx The canvas 2D context object to draw into.
343 * @param {Boolean} [ignoreCache=false] Indicates whether the draw operation should ignore any current cache.
344 * For example, used for drawing the cache (to prevent it from simply drawing an existing cache back
345 * into itself).
346 * @return {Boolean}
347 **/
348 p.draw = function(ctx, ignoreCache) {
349 if (this.DisplayObject_draw(ctx, ignoreCache)) { return true; }
350 var img = this.image, rect = this.sourceRect;
351 if (img.getImage) { img = img.getImage(); }
352 if (!img) { return true; }
353 if (rect) {
354 // some browsers choke on out of bound values, so we'll fix them:
355 var x1 = rect.x, y1 = rect.y, x2 = x1 + rect.width, y2 = y1 + rect.height, x = 0, y = 0, w = img.width, h = img.height;
356 if (x1 < 0) { x -= x1; x1 = 0; }
357 if (x2 > w) { x2 = w; }
358 if (y1 < 0) { y -= y1; y1 = 0; }
359 if (y2 > h) { y2 = h; }
360 ctx.drawImage(img, x1, y1, x2-x1, y2-y1, x, y, x2-x1, y2-y1);
361 } else {
362 ctx.drawImage(img, 0, 0);
363 }
364 return true;
365 };
366
367 //Note, the doc sections below document using the specified APIs (from DisplayObject) from
368 //Bitmap. This is why they have no method implementations.
369
370 /**
371 * Because the content of a Bitmap is already in a simple format, cache is unnecessary for Bitmap instances.
372 * You should <b>not</b> cache Bitmap instances as it can degrade performance.
373 *
374 * <strong>However: If you want to use a filter on a Bitmap, you <em>MUST</em> cache it, or it will not work.</strong>
375 * To see the API for caching, please visit the DisplayObject {{#crossLink "DisplayObject/cache"}}{{/crossLink}}
376 * method.
377 * @method cache
378 **/
379
380 /**
381 * Because the content of a Bitmap is already in a simple format, cache is unnecessary for Bitmap instances.
382 * You should <b>not</b> cache Bitmap instances as it can degrade performance.
383 *
384 * <strong>However: If you want to use a filter on a Bitmap, you <em>MUST</em> cache it, or it will not work.</strong>
385 * To see the API for caching, please visit the DisplayObject {{#crossLink "DisplayObject/cache"}}{{/crossLink}}
386 * method.
387 * @method updateCache
388 **/
389
390 /**
391 * Because the content of a Bitmap is already in a simple format, cache is unnecessary for Bitmap instances.
392 * You should <b>not</b> cache Bitmap instances as it can degrade performance.
393 *
394 * <strong>However: If you want to use a filter on a Bitmap, you <em>MUST</em> cache it, or it will not work.</strong>
395 * To see the API for caching, please visit the DisplayObject {{#crossLink "DisplayObject/cache"}}{{/crossLink}}
396 * method.
397 * @method uncache
398 **/
399
400 /**
401 * Docced in superclass.
402 */
403 p.getBounds = function() {
404 var rect = this.DisplayObject_getBounds();
405 if (rect) { return rect; }
406 var image = this.image, o = this.sourceRect || image;
407 var hasContent = (image && (image.naturalWidth || image.getContext || image.readyState >= 2));
408 return hasContent ? this._rectangle.setValues(0, 0, o.width, o.height) : null;
409 };
410
411 /**
412 * Returns a clone of the Bitmap instance.
413 * @method clone
414 * @param {Boolean} node Whether the underlying dom element should be cloned as well.
415 * @return {Bitmap} a clone of the Bitmap instance.
416 **/
417 p.clone = function(node) {
418 var image = this.image;
419 if(image && node){ image = image.cloneNode(); }
420 var o = new Bitmap(image);
421 if (this.sourceRect) { o.sourceRect = this.sourceRect.clone(); }
422 this._cloneProps(o);
423 return o;
424 };
425
426 /**
427 * Returns a string representation of this object.
428 * @method toString
429 * @return {String} a string representation of the instance.
430 **/
431 p.toString = function() {
432 return "[Bitmap (name="+ this.name +")]";
433 };
434
435
436 createjs.Bitmap = createjs.promote(Bitmap, "DisplayObject");
437}());
438
439 </pre>
440</div>
441
442 </div>
443 </div>
444 </div>
445 </div>
446 </div>
447</div>
448<script src="../assets/vendor/prettify/prettify-min.js"></script>
449<script>prettyPrint();</script>
450<script src="../assets/js/yui-prettify.js"></script>
451<script src="../assets/../api.js"></script>
452<script src="../assets/js/api-filter.js"></script>
453<script src="../assets/js/api-list.js"></script>
454<script src="../assets/js/api-search.js"></script>
455<script src="../assets/js/apidocs.js"></script>
456</body>
457</html>