as3.0 slicing bitmaps

Source: Internet
Author: User

For bitmap slicing, we can use BitmapData's CopyPixels function, here is a code instance

Import flash.display.loader;import flash.net.urlrequest;import flash.display.bitmap;import  flash.display.BitmapData;import flash.events.Event;import flash.geom.Rectangle;import  Flash.geom.point;import flash.display.sprite;var loader:loader = new loader (); var  imgurl:urlrequest = new urlrequest (' 123.jpg '); Loader.contentLoaderInfo.addEventListener ( Event.complete,load_complete); Loader.load (Imgurl); Function load_complete (evt:event):void{var  sourcebitmap = evt.target.loader.content as bitmap;//equivalent to loader.content as  bitmapvar splitehorizon = 8;var splitevertical = 5;var chorizonlength  = sourcebitmap.width/splitehorizon;var cverticallength = sourcebitmap.height/ Splitevertical;trace (chorizonlength+ ', ' +cverticallength); var margin_top = 5;var margin_ Left = 5;for (var i=0 ; i<  splitevertical ; i++) {for (var j=0 ; j<splitehorizon ; j++) {var  sprite:sprite = new sprite (); Var ret:rectangle = new rectangle (j  * cHorizonLength, i * cVerticalLength , cHorizonLength ,  Cverticallength); Var bitmapdest:bitmap = new bitmap (New bitmapdata (200,200)); Bitmapdest.bitmapData.copyPixels (Sourcebitmap.bitmapdata , ret,new point (0,0)); Sprite.addchild ( Bitmapdest);sprite.x = j *  (chorizonlength +margin_left); sprite.y = i*   (cverticallength + margin_top); AddChild (sprite);}}

The results of the implementation are as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6E/F1/wKioL1WMw__jY-zaAASeBPTGUdA298.jpg "title=" 2015-06-26_110720.png "alt=" Wkiol1wmw__jy-zaaasebptguda298.jpg "/>

as3.0 slicing bitmaps

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.