flash as3.0 拍照片功能
我们主要用到sprite这个内库来实现的喽,好了费话不说多了我们看看吧。
var show_mm:Mm=new Mm(0,0);
var show_bmp:Bitmap =new Bitmap(show_mm);
addChild(show_bmp);
var border_sprite:Sprite;
var copy_bmp:Bitmap =new Bitmap;
addChild(copy_bmp);
var left_point:Point =new Point;
var right_point:Point =new Point;
var start_point:Point =new Point;
function MouseDownHandler(_evt:MouseEvent):void {
root.border_sprite=new Sprite;
addChild(root.border_sprite);
start_point.x=stage.mouseX;
start_point.y=stage.mouseY;
stage.addEventListener(MouseEvent.MOUSE_MOVE ,MouseMoveHandler);
stage.addEventListener(MouseEvent.MOUSE_UP ,MouseUpHandler);
}
function MouseMoveHandler(_evt:MouseEvent):void {
right_point.x=Math.max (stage.mouseX,start_point.x);
right_point.y=Math.max (stage.mouseY,start_point.y);
left_point.x=Math.min (stage.mouseX,start_point.x);
left_point.y=Math.min (stage.mouseY,start_point.y);
border_sprite.graphics.clear();
border_sprite.graphics.lineStyle(1,0xff0000);
border_sprite.graphics.moveTo(left_point.x,left_point.y);
border_sprite.graphics.lineTo(right_point.x,left_point.y);
border_sprite.graphics.lineTo(right_point.x,right_point.y);
root.border_sprite.graphics.lineTo(left_point.x,right_point.y);
root.border_sprite.graphics.lineTo(left_point.x,left_point.y);
}
function MouseUpHandler(_evt:MouseEvent):void {
root.border_sprite.graphics.clear();
var _bmd:BitmapData =new BitmapData(stage.width,stage.height);
_bmd.draw(stage);
var _rectangle:Rectangle =new Rectangle(left_point.x,left_point.y,right_point.x-left_point.x,right_point.y-left_point.y);
var new_bmd:BitmapData =new BitmapData(right_point.x-left_point.x,right_point.y-left_point.y);
new_bmd.copyPixels(_bmd,_rectangle,new Point(0,0));
copy_bmp.bitmapData =new_bmd;
stage.removeEventListener(MouseEvent.MOUSE_MOVE ,MouseMoveHandler);
stage.removeEventListener(MouseEvent.MOUSE_UP ,MouseUpHandler);
}
stage.addEventListener(MouseEvent.MOUSE_DOWN ,MouseDownHandler);
补充:flash教程,As3.0