在Flash中的“填充和描边”选项下,您可以将形状着色为库中的一个纹理。示例:http://i1.minus.com/iban9aRUCI7UTf.png
如何使用AS3代码执行此操作?
答案 0 :(得分:1)
如果您使用Graphics
API进行绘图,则可以使用beginBitmapFill。
打开库中图像的属性,然后在“ActionScript”选项卡上选中“导出for ActionScript ”。给它一个类名,例如“ MyTexture ”,然后就可以像这样使用它:
var texturedCircle:Sprite = new Sprite();
texturedCircle.graphics.beginBitmapFill(new MyTexture());
texturedCircle.graphics.drawCircle(0, 0, 100);
答案 1 :(得分:0)
您可以分两步完成此操作。
function averageColour(source:BitmapData):uint {
var red:Number = 0;
var green:Number = 0;
var blue:Number = 0;
var count:Number = 0;
var pixel:Number;
for (var x:int = 0; x < source.width; x++) {
for (var y:int = 0; y < source.height; y++) {
pixel = source.getPixel(x, y);
red += pixel >> 16 & 0xFF;
green += pixel >> 8 & 0xFF;
blue += pixel & 0xFF;
count++
}
}
red /= count;
green /= count;
blue /= count;
return red << 16 | green << 8 | blue;
}
function averageColour(source:BitmapData):uint {
var red:Number = 0;
var green:Number = 0;
var blue:Number = 0;
var count:Number = 0;
var pixel:Number;
for (var x:int = 0; x < source.width; x++) {
for (var y:int = 0; y < source.height; y++) {
pixel = source.getPixel(x, y);
red += pixel >> 16 & 0xFF;
green += pixel >> 8 & 0xFF;
blue += pixel & 0xFF;
count++
}
}
red /= count;
green /= count;
blue /= count;
return red << 16 | green << 8 | blue;
}
function setColor(obj:Object, color:uint, alpha:Number = 1):void {
/* Colors the object using uint */
// Pull the individual primaries
var r:Number = (color >> 16 ) & 0xFF;
var g:Number = (color >> 8) & 0xFF;
var b:Number = color & 0xFF;
obj.transform.colorTransform = new ColorTransform(0,0,0,alpha,r,g,b,0);
}