【问题标题】:How to get blob image from mysql to as3 with php and addChild it in a way of getting byteArray and converting it to image?如何使用 php 将 blob 图像从 mysql 获取到 as3 并以获取 byteArray 并将其转换为图像的方式添加它?
【发布时间】:2013-12-20 04:41:49
【问题描述】:

如何使用php从mysql获取blob图像到as3并以获取byteArray并将其转换为图像的方式addChild?

这是php:

if($RequestType == 'Select'){

  while($row=mysql_fetch_assoc($results)){
      $arrdata[]=$row;
  }

  foreach($arrdata as $key=>$value){
    $output[$key] =  $arrdata[$key];
    $output[$key]['png'] = base64_encode($arrdata[$key]['png']);
  }

header('Content-type: application/json');
print(json_encode($output));

我已经有了类似的东西,但更长:

VBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAACXBIWXMAAC4jAAAuIwF4pT92AAAYxUlEQVR42u1bB3Sc1ZWe8k / vvfem6aPpGk2RZjQzGrVRl6xiyZZkWS4gFxyDGyEsxjE1gVBTSGAdQg4keyCxF4NsY1pCDARsBwiE4pBsIJjN7nKWgM3eJ7 / hTDhUIyJyNj7nHh3P / DP / f79373e / e98b0oUXXkj6 / 2ykfwLwTwAW58br1q0j9fX1UQcGBpgjw0Pcy P>

【问题讨论】:

    标签: php image actionscript-3 blob addchild


    【解决方案1】:

    (这里我假设你已经处理了 HTTP 请求结果)

    要将base64编码的图像转换为DisplayObject,首先需要将Base64解码为ByteArray,然后使用Loader类加载图像内容,监听Loader的@987654325 @要调度的事件。获得该事件后,Loader.content 将包含一个 DisplayObject,您可以使用 addChild() 将其添加到屏幕。

    示例:(编辑:添加了一个Array 来跟踪加载的对象,以便它们被请求并更改函数来应对)

    private var countLoadedImages:int = 0;//track how many images have loaded
    private var arrImageLoaders:Array = new Array();//store loaders for call back
        public function loadImageFromBase64(yourBase64:String):void
        {
            var base64:Base64Decoder = new Base64Decoder();
            base64.decode(yourBase64);//decode your image
    
            var data:ByteArray = base64.toByteArray();//convert to byte array
    
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete);
            arrImageLoaders.push(loader.contentLoaderInfo);//add to array in order func was called
            loader.loadBytes(data);//hand over to Loader
        }
        protected function onLoadComplete(event:Event):void
        {
            countLoadedImages++;
            event.target.removeEventListener(Event.COMPLETE,onLoadComplete);
            if (countLoadedImages == arrImageLoaders.length)
            {
                 allImagesLoaded();
            }
        }
        protected function allImagesLoaded():void
        {
            var contentLoaderInfo:LoaderInfo
            for (var x:int = 0; x<arrImageLoaders.length; x++)
            {
                contentLoaderInfo = arrImageLoaders[x] as LoaderInfo;
                addChild(contentLoaderInfo.content);
            }
        }
    

    【讨论】:

    • 修复错误:“将静态类型 Object 的值隐式强制转换为可能不相关的类型 flash.display:LoaderInfo。” - 只需将作为 LoaderInfo 添加到 event.target。
    • var contentLoaderInfo:LoaderInfo = event.target as LoaderInfo; 抱歉忘记添加 cast 语句,这应该可以解决该错误
    • 没问题! =) 只为别人。 ^_^
    • 帮助。当我打电话时,@ 987654332@ 在循环中并回调contenLoaderInfo.content 它返回错误的图像,而不是首先。你知道为什么吗?
    • 它以错误的方式对图像进行排序。那是因为loadBytes 是异步方法吗?
    猜你喜欢
    • 2013-03-28
    • 1970-01-01
    • 2020-09-02
    • 2018-11-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 2019-09-10
    • 1970-01-01
    相关资源
    最近更新 更多