[]image.drawToCanvas方法获取的一直是空的png

通过ide创建的image,只赋值了skin,image.drawToCanvas方法获取的一直是空的png
已邀请:

cuixueying

赞同来自:

你创建好了Image,不要立即drawToCanvas,加个延迟或者点击行为,譬如
package
{
import laya.display.Sprite;
import laya.display.Stage;
import laya.resource.HTMLCanvas;
import laya.resource.Texture;
import laya.ui.Image;
import laya.utils.Handler;
import laya.webgl.WebGL;

public class LayaAirDemo
{
private var img:Image;
public function LayaAirDemo()
{
Laya.init(800, 600, WebGL);
Laya.stage.alignV = Stage.ALIGN_MIDDLE;
Laya.stage.alignH = Stage.ALIGN_CENTER;
Laya.stage.scaleMode = Stage.SCALE_SHOWALL;
Laya.stage.bgColor = "#232628";
Laya.loader.load("res/logo.png",Handler.create(this,onLoaded));
}

private function onLoaded():void
{
img=new Image();
img.skin="res/logo.png";
Laya.stage.addChild(img);
Laya.timer.once(500,this,onClick);
//Laya.stage.on(Event.CLICK,this,onClick);
}

private function onClick():void
{
var htmlCanvas:HTMLCanvas=img.drawToCanvas(100,100,0,0) as HTMLCanvas;
var texture:Texture=new Texture(htmlCanvas);
var sp:Sprite=new Sprite();
sp.graphics.drawTexture(texture,0,0,100,100);
Laya.stage.addChild(sp);
sp.x=200;
}
}
}

要回复问题请先

商务合作
商务合作