• AS3.0 关于用URLLoader加载外部图片


    用URLLoader以二进制的方式加载外部图片,获得URLLoader.data的ByteArray数据,再用Loader去加载,这时Loader.content就是一个bitmap了。
    package {
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.ConvolutionFilter;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import flash.utils.ByteArray;
       
    public class Main extends Sprite{
    private var loader:URLLoader;
    public function Main():void
    {
      loadImage("image.jpg");
    }
    private function loadImage(_path:String ):void
    {
      loader = new URLLoader;
      loader.dataFormat=URLLoaderDataFormat.BINARY ;
      loader.addEventListener (Event.COMPLETE , onImageLoaded);
          loader.load(new URLRequest (_path));
    }
    private function onImageLoaded(e:Event):void
    {
      var _ba:ByteArray = e.target.data as ByteArray;
      var _l:Loader = new Loader;
      _l.contentLoaderInfo.addEventListener (Event.COMPLETE, onBytesLoaded);
      _l.loadBytes(_ba);
     
      loader.removeEventListener (Event.COMPLETE , onImageLoaded);
      loader = null;
    }
                    
    private function onBytesLoaded(e:Event):void 
    {
      var _bitmap:Bitmap = e.target.content as Bitmap;
      trace(_bitmap.width, _bitmap.height );
      addChild (_bitmap );
     
      e.target.loader.contentLoaderInfo.removeEventListener (Event.COMPLETE, onBytesLoaded);
    }                
    }
    }
  • 相关阅读:
    函数的参数设置
    定义函数
    使用dict和set
    (转)set集合的应用
    循环与range
    if语句
    How to use git hub
    Install pyodbc in OpenSUSE
    Ubuntu编译安装PHP7
    Ubuntu为已经安装的PHP7单独编译mysqli
  • 原文地址:https://www.cnblogs.com/atong/p/2872228.html
Copyright © 2020-2023  润新知