package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.events.Event; import flash.events.MouseEvent; import flash.net.FileReference; import flash.utils.ByteArray; import flash.utils.Endian; public class BMPread extends Sprite { private var fr:FileReference; public function BMPread() { stage.addEventListener(MouseEvent.CLICK,onClick); } private function onClick(event:MouseEvent):void{ fr=new FileReference(); fr.addEventListener(Event.SELECT,onSelect); fr.addEventListener(Event.COMPLETE,onComplete); fr.browse(); } private function onSelect(e:Event):void{ fr.load(); } private function onComplete(e:Event):void{ var ba:ByteArray=fr.data; ba.endian=Endian.LITTLE_ENDIAN; ba.position=10; var pixelOffset:uint=ba.readUnsignedInt(); ba.position+=4; var width:int=ba.readInt(); var height:int=ba.readInt(); ba.position=pixelOffset; var padding:int=(width*3)%4; trace(width+":"+height); var bmd:BitmapData=new BitmapData(width,height,false); for(var y:int=height-1;y>=0;--y){ for(var x:int=0;x<width;++x){ bmd.setPixel(x,y,ba.readUnsignedByte()| ba.readUnsignedByte()<<8| ba.readUnsignedByte()<<16); } ba.position+=padding; } addChild(new Bitmap(bmd)); } } }