Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Apache flex Can';t从Flex Air AS3中丢弃的图像中获取位图数据_Apache Flex_Image_Drag And Drop_Air_Bitmapdata - Fatal编程技术网

Apache flex Can';t从Flex Air AS3中丢弃的图像中获取位图数据

Apache flex Can';t从Flex Air AS3中丢弃的图像中获取位图数据,apache-flex,image,drag-and-drop,air,bitmapdata,Apache Flex,Image,Drag And Drop,Air,Bitmapdata,当我把图像放到画布上时,我可以得到图像的本机路径,但不能得到我需要的位图数据 在调试模式下,当我查看文件属性时,数据被设置为NULL 我做错了什么?在我的代码文件中。数据没有给我任何信息 protected function creationCompleteHandler(event:FlexEvent):void { this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER,onDragIn); this.addEventL

当我把图像放到画布上时,我可以得到图像的本机路径,但不能得到我需要的位图数据

在调试模式下,当我查看文件属性时,数据被设置为NULL

我做错了什么?在我的代码
文件中。数据
没有给我任何信息

protected function creationCompleteHandler(event:FlexEvent):void
{
    this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER,onDragIn);
    this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP,onDrop);
    NativeDragActions.COPY;
}

        private function onDrop(e:NativeDragEvent):void
        {
            trace("Dropped!");

            var dropfiles:Array = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT) as Array;
            for each (var file:File in dropfiles){
                switch (file.extension.toLowerCase()){
                    case "png" :
                        trace('png');
                        //resizeImage(file.nativePath);
                        break;
                    case "jpg" :
                        trace('jpg');
                        //resizeImage(file.nativePath);
                        break;
                    case "jpeg" :
                        trace('jpeg');
                        //resizeImage(file.nativePath);
                        break;
                    case "gif" :
                        resizeImage(file.nativePath);
                        break;
                    default:
                        Alert.show("choose an image file!");
                }
            }
        }

首先,您必须加载bytearray:

var ba:ByteArray = new ByteArray();
var stream:FileStream = new FileStream();
stream.open(file, FileMode.READ);
stream.readBytes(ba);
stream.close();
接下来,使用以下命令加载位图:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, fileLoaded);
loader.loadBytes(ba);
最后,获取位图

private function fileLoaded(event:Event):void {
    var bitmap:Bitmap = Bitmap(event.target.content);

    // finally you have:   bitmap.bitmapData

    // cleanup
    loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, fileLoaded);
}