fp10.1 中位图填充

package
{
import flash.display.*;
import flash.events.MouseEvent;

[SWF(backgroundColor=0xffffff,width='1024',height='600')]
public class BitmapTriangleUV2 extends Sprite {

[Embed(source='image.jpg')]
private var ImageClass:Class;

private var handle0:Sprite;
private var handle1:Sprite;
private var handle2:Sprite;
private var handle3:Sprite;
private var bitmap:Bitmap;
private var vertices:Vector.<Number> = new Vector.<Number>();
private var uvData:Vector.<Number> = new Vector.<Number>();
private var indices:Vector.<int> = new Vector.<int>();

public function BitmapTriangleUV2() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//创建拖动点
handle0 = makeHandle(100,100);
handle1 = makeHandle(200,100);
handle2 = makeHandle(200,200);
handle3 = makeHandle(100,200);

uvData.push(0,0);
uvData.push(1,0);
uvData.push(1,1);
uvData.push(0,1);

//创建三角形
indices.push(0,1,2);
indices.push(2,3,0);

bitmap = new ImageClass() as Bitmap;
draw();
}

//拖动点
private function makeHandle(xpos:Number, ypos:Number):Sprite {
var handle:Sprite = new Sprite();
handle.graphics.beginFill(0);
handle.graphics.drawCircle(0,0,5);
handle.graphics.endFill();
handle.addEventListener(MouseEvent.MOUSE_DOWN, handlerMouseDown);
handle.x = xpos;
handle.y = ypos;
this.addChild(handle);
return handle;
}

private function handlerMouseDown(e:MouseEvent):void {
e.target.startDrag();
stage.addEventListener( MouseEvent.MOUSE_MOVE, onMouseMove );
stage.addEventListener( MouseEvent.MOUSE_UP, onMouseUp );
}

private function onMouseMove( e:MouseEvent ):void {
draw();
}

private function onMouseUp( e:MouseEvent ):void {
stopDrag();
stage.removeEventListener( MouseEvent.MOUSE_MOVE, onMouseMove );
stage.removeEventListener( MouseEvent.MOUSE_UP, onMouseUp );
}

//bitmap填充
private function draw():void {
vertices[0] = handle0.x;
vertices[1] = handle0.y;
vertices[2] = handle1.x;
vertices[3] = handle1.y;
vertices[4] = handle2.x;
vertices[5] = handle2.y;
vertices[6] = handle3.x;
vertices[7] = handle3.y;
this.graphics.clear();
this.graphics.beginBitmapFill(bitmap.bitmapData);
this.graphics.drawTriangles(vertices, indices, uvData);
this.graphics.endFill();
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值