上传图像然后共享而不使用sharedObject或任何东西保存Flex上的文件?

时间:2011-06-10 02:46:55

标签: flex image sharing

我正在进行聊天,上传图片并分享。问题是我可以上传和显示图像,但我无法将其分享给另一方。

以下是一些代码:

public var photo:FileReference = new FileReference();

protected function crop_clickHandler(event:MouseEvent):void
{
    var f:FileFilter = new FileFilter("Image", "*.jpg;*.jpeg;*;*.gif;*.png;*");
    photo.addEventListener(Event.SELECT, fileSelected);
    photo.browse([f]);
}

private function fileSelected(evt:Event):void
{
    photo.addEventListener(Event.COMPLETE,loadCompleted);
    photo.load();
}

private var loader : Loader = new Loader();

private function loadCompleted(evt:Event):void
{
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, getBitmapData);
    loader.loadBytes(photo.data);
}

private function getBitmapData(event:Event):void
{
    var content:* = loader.content;
    var BMPData:BitmapData = new BitmapData(content.width,content.height);

    var UIMatrix:Matrix = new Matrix();
    BMPData.draw(content, UIMatrix);

    var imgObj:Object = new Object();
    imgObj.client = username.text;
    imgObj.img = BMPData;
    imgSO.setProperty("image",imgObj);
}           

private function imagehandler(SEvt:SyncEvent):void
{
    if(imgSO.data.image)
    {
        var imgObj:Object = imgSO.data.image;
        var p:ParagraphElement = new ParagraphElement();
        var image:InlineGraphicElement = new InlineGraphicElement();

        image.source = new Bitmap(imgObj.img);
        p.addChild(senderName(imgObj.client));
        p.addChild(image);
        chatWindow.textFlow.addChild(p);
    }   
}

1 个答案:

答案 0 :(得分:0)

如果您定位到Flash Player 10,则可以尝试使用FileReference类。快速(未经测试)的例子:

protected function exportImage():void
{
  var imageToSave:ImageSnapshot = ImageSnapshot.captureImage(image, 300, new PNGEncoder());
  var file:FileReference = new FileReference();
  file.save(imageToSave.data, "my_image_name.png");
}