0

画像をキャンバスにドロップすると、画像へのnativePathを取得できますが、必要なビットマップデータは取得できません。

デバッグモードでファイルのプロパティを調べると、データはNULLに設定されています。

私はここで何が間違っているのですか?私のコードfile.dataでは何も与えられません。

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!");
                }
            }
        }
4

1 に答える 1

0

まず、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);
}
于 2011-05-11T12:49:58.527 に答える