Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash 在AS3中创建图像_Flash_Actionscript 3 - Fatal编程技术网

Flash 在AS3中创建图像

Flash 在AS3中创建图像,flash,actionscript-3,Flash,Actionscript 3,是否可以在Flash AS3中创建包含用户输入的特定bagroundcolor和som文本的图像?然后在运行时使用此映像 //尼克当然可以: function createTextBox ( width : Number, height : Number, bgColor : uint, text : String, texFormat : TextFormat ) : Sprite { var sprite : Sprite = new Sprite(); var shap

是否可以在Flash AS3中创建包含用户输入的特定bagroundcolor和som文本的图像?然后在运行时使用此映像

//尼克

当然可以:

function createTextBox
(
 width : Number,
 height : Number, 
 bgColor : uint, 
 text : String, 
 texFormat : TextFormat ) : Sprite
{
 var sprite : Sprite = new Sprite();
 var shape : Shape = new Shape();
 var textField : TextField = new TextField();

 //background
 shape.graphics.beginFill( bgColor );
 shape.graphics.drawRect( 0, 0, width, height );
 sprite.addChild( shape );

 //textfield
 textfield.width = width;
 textfield.height = height;
 textfield.multiline = true;
 textfield.wordWrap = true;

 //up to you if it serves your needs
 textfield.embedFonts = true;
 textField.selectable = false;

 textField.defaultTextFormat = textFormat;
 sprite.addChild( textField );

 return sprite;
}

var format : TextFormat = new TextFormat();
format.color = 0xFF0000;
format.size = 12;

var myText : String = "A woman is just a woman but a good cigar is a smoke!"

var sprite : Sprite = createTextBox( 200, 200, 0x999999, myText, format );
addChild( sprite );

//if you want, you can covert this to a bitmap:

var bitmapData : BitmapData = new BitmapData( 200, 200, false );
bitmapData.draw( sprite );

var bitmap : Bitmap = new Bitmap( bitmapData );
bitmap.x = 200;
addChild( bitmap );

下面是一段伪代码,可以帮助您绘制图形并创建位图对象

w = 400;
h = 400;

var shape:Shape = new Shape();
shape.graphics.beginFill( 0xFF0000, 1 );
shape.graphics.drawRect( 0, 0, w, h );
shape.graphics.endFill();

var field:TextField = new TextField();
field.text = someUserInput;
shape.addChild( field );

var bitmap:Bitmap = new Bitmap();
var bitmapData:BitmapData = new BitmapData( w, h );
bitmapData.draw( shape );
bitmap.bitmapData = bitmapData;

addChild( bitmap );
从这里,您可以使用Adobe core libs创建实际的jpeg或png文件:

var jpgEncoder:JPGEncoder = new JPGEncoder( quality );
var jpgStream:ByteArray = jpgEncoder.encode( bitmapData );