如何创建具有透明边框和圆角的Flex图像?

时间:2012-03-21 19:32:37

标签: actionscript-3 flex flex4 flex4.5 flex4.6

我在Flex项目中有一张照片:

Image without transparent border and rounded corners

<s:Image source="@Embed('images/photo.png')" />

但现在我想知道我是否可以将此图像设为下图,在Flex(4 / 4.5 / 4.6) (在MXML和/或 ActionScript 3中)

Image with transparent border and rounded corners

这可能吗?

2 个答案:

答案 0 :(得分:1)

这是您应该能够移植到Flex的feathering mask tutorial in flash

答案 1 :(得分:0)

是的,首先你需要使用AI或PS为圆角和内阴影创建一个遮罩层

  1. 在Photoshop或AI中创建蒙版。如果你正在使用PS,它必须是一个矢量蒙版。
  2. 将其导入Flash催化剂。如果您使用PS,则必须在导入对话框中选择“形状图层&gt;保持可编辑”。
  3. 在图层面板中,您会看到一个包含屏蔽内容的组。任何进入该组的东西都会被掩盖。
  4. 在蒙版组中添加一个图像,并在Flash催化剂的代码视图中复制蒙版代码。 (FC)
  5. 现在为spark图像创建一个外观类,并在imageDisplay(BitmapImage)上方添加蒙版代码。

    <强> MaskedImageSkin.mxml

    <?xml version="1.0" encoding="utf-8"?>
    <s:Skin xmlns:fx="http://ns.adobe.com/mxml/2009" 
            xmlns:s="library://ns.adobe.com/flex/spark" 
            xmlns:fb="http://ns.adobe.com/flashbuilder/2009"
            alpha.disabled="0.5">
    
        <s:states>
            <s:State name="uninitialized" />
            <s:State name="loading"/>
            <s:State name="ready" />
            <s:State name="invalid" />
            <s:State name="disabled" />
        </s:states>
    
        <fx:Script fb:purpose="styling">
            <![CDATA[         
                /**
                 *  @private
                 */
                override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number) : void
                {
                    // Push backgroundColor and backgroundAlpha directly.
                    // Handle undefined backgroundColor by hiding the background object.
                    if (isNaN(getStyle("backgroundColor")))
                    {
                        background.visible = false;
                        background.includeInLayout = false;
                    }
                    else
                    {
                        background.visible = true;
                        background.includeInLayout = true;
                        bgFill.color = getStyle("backgroundColor");
                        bgFill.alpha = getStyle("backgroundAlpha");
                    }
    
                    super.updateDisplayList(unscaledWidth, unscaledHeight);
                }
            ]]>        
        </fx:Script>
    
        <!-- host component -->
        <fx:Metadata>
            <![CDATA[ 
            /** 
            * @copy spark.skins.spark.ApplicationSkin#hostComponent
             */
            [HostComponent("spark.components.Image")]
            ]]>
        </fx:Metadata>
    
        <!--- Defines the appearance of the image background. -->
        <s:Rect id="background" left="0" right="0" top="0" bottom="0">
            <s:fill>
                <!-- @private -->
                <s:SolidColor id="bgFill"/>
            </s:fill>
        </s:Rect>
    
        <s:Group x="0" y="0">
            <s:filters>
                <s:DropShadowFilter color="#FFFFFF" inner="true" blurX="10" blurY="10" quality="5" alpha="0.85" angle="45" distance="10" />
                <s:DropShadowFilter color="#FFFFFF" inner="true" blurX="10" blurY="10" quality="5" alpha="0.85" angle="90" distance="10"/>
                <s:DropShadowFilter color="#FFFFFF" inner="true" blurX="10" blurY="10" quality="5" alpha="0.85" angle="-45" distance="10" />
                <s:DropShadowFilter color="#FFFFFF" inner="true" blurX="10" blurY="10" quality="5" alpha="0.85" angle="-90" distance="10"/>
            </s:filters>
            <s:mask>
                <s:Group x="0" y="0" width="280" height="180" >
                    <s:Rect left="0" right="0" top="0" bottom="0" radiusX="10" radiusY="10">
                        <s:fill>
                            <s:SolidColor color="#FFFFFF"/>
                        </s:fill>
                    </s:Rect>
                </s:Group>
    
            </s:mask>
    
            <!--- Primary image display skin part. -->
            <s:BitmapImage id="imageDisplay" left="0" top="0" right="0" bottom="0"/>
    
        </s:Group>
    
    
    
    
        <!--- Progress indicator skin part. -->
        <s:Range id="progressIndicator" skinClass="spark.skins.spark.ImageLoadingSkin" verticalCenter="0" horizontalCenter="0" includeIn="loading" layoutDirection="ltr" />
    
        <!--- Icon that appears in place of the image when an invalid image is loaded. -->
        <s:BitmapImage id="brokenImageIcon" includeIn="invalid" source="@Embed(source='Assets.swf',symbol='__brokenImage')" verticalCenter="0" horizontalCenter="0"/>
    
    </s:Skin>
    

    将此皮肤类应用于火花图像

    <s:Image source="@Embed('assets/maskImg.png')" skinClass="MaskedImageSkin" width="200" height="200"/>
    

    上面的代码只是屏蔽图像的一个例子,使用圆角矩形创建自己的蒙版。这将解决您的问题。

    is it looks like what you want ?

    快乐的皮肤......