1 /** 2 * Hilo 3 * Copyright 2015 alibaba.com 4 * Licensed under the MIT License 5 */ 6 7 /** 8 * <iframe src='../../../examples/Bitmap.html?noHeader' width = '300' height = '200' scrolling='no'></iframe> 9 * <br/> 10 * Example: 11 * <pre> 12 * var bmp = new Hilo.Bitmap({image:imgElem, rect:[0, 0, 100, 100]}); 13 * stage.addChild(bmp); 14 * </pre> 15 * @class Bitmap 16 * @augments View 17 * @param {Object} properties the options of create Instance.It can contains all writable property and Moreover: 18 * <ul> 19 * <li><b>image</b> - the image of bitmap which contained, required.</li> 20 * <li><b>rect</b> - the range of bitmap in the image, option</li> 21 * <li><b>crossOrigin</b> - Whether cross-domain is needed, default is false</li> 22 * </ul> 23 * @module hilo/view/Bitmap 24 * @requires hilo/core/Hilo 25 * @requires hilo/core/Class 26 * @requires hilo/view/View 27 * @requires hilo/view/Drawable 28 */ 29 var Bitmap = Class.create(/** @lends Bitmap.prototype */{ 30 Extends: View, 31 constructor: function(properties){ 32 properties = properties || {}; 33 this.id = this.id || properties.id || Hilo.getUid("Bitmap"); 34 Bitmap.superclass.constructor.call(this, properties); 35 36 this.drawable = new Drawable(properties); 37 38 //init width and height 39 if(!this.width || !this.height){ 40 var rect = this.drawable.rect; 41 if(rect){ 42 this.width = rect[2]; 43 this.height = rect[3]; 44 } 45 } 46 }, 47 48 /** 49 * set the image。 50 * @param {Image|String} Image Object or URL. 51 * @param {Array} rect the range of bitmap in the image, option. 52 * @param {Boolean} crossOrigin Whether cross-domain is needed, default is false. 53 * @returns {Bitmap} self。 54 */ 55 setImage: function(image, rect, crossOrigin){ 56 this.drawable.init({image:image, rect:rect, crossOrigin:crossOrigin}); 57 if(rect){ 58 this.width = rect[2]; 59 this.height = rect[3]; 60 } 61 else if(!this.width && !this.height){ 62 rect = this.drawable.rect; 63 if(rect){ 64 this.width = rect[2]; 65 this.height = rect[3]; 66 } 67 } 68 return this; 69 } 70 }); 71