如何在flex应用程序中拆分图像

时间:2013-03-16 15:06:11

标签: image actionscript-3 flex actionscript bitmap

如何在flex应用程序中拆分此图像。 事实上,我正在考虑从xml调用一个图像并将其拆分为“flex application”

我尝试了一些方法。但它不起作用!
我很乐意为你提供帮助。

 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"  initialize="image_loader_completeHandler(event)">
<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;


        protected function image_loader_completeHandler(event:Event):void
        {
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, leftpart);
            loader.load( new URLRequest("http://www.helpexamples.com/flash/images/image1.jpg"));



            function leftpart(e:Event):void 
            {


                var bmpd1:BitmapData = new BitmapData    (loader.width/2,loader.height,false)

                bmpd1.draw(loader,null,null,null,rec);

                var rec:Rectangle = new Rectangle   (0,0,bmpd1.width,bmpd1.height);

                var bmp:Bitmap = new Bitmap (bmpd1);


                image_loader.addChild(bmp);

            }
        }

    ]]>
</fx:Script>


<s:Image id="image_loader"   />

1 个答案:

答案 0 :(得分:0)

不要将位图添加到图像元素,只需将bitmapData设置为源:

function leftpart(e:Event):void 
{
    var bmpd1:BitmapData = new BitmapData    (loader.width/2,loader.height,false)
    bmpd1.draw(loader);
    image_loader.source = bmpd1;
}

您甚至不必创建Bitmap对象,source接受BitmapData