将掩码添加到Flex Image

时间:2011-05-25 00:59:29

标签: flex flex4

我有以下mxml:

<s:Image source="@Embed(source='my/path/to/img.png')" >
  <flex:mask>
    <s:Group alpha="0.1">
      <s:Rect width="129" height="123">
        <s:fill>
          <s:SolidColor color="0x00FFFF"/>
        </s:fill>
      </s:Rect>
    </s:Group>
  </flex:mask>
</s:Image>

此代码不应生成129px * 123px的矩形蒙版,会产生裁剪效果吗?

感谢。

3 个答案:

答案 0 :(得分:2)

问题是掩码对象需要已经创建并添加到显示列表中,直到它被设置为掩码。因此,您的代码应该更改以反映这一点,如下所示:

<s:Group id="imageMask" alpha="0.1">
  <s:Rect width="129" height="123">
    <s:fill>
      <s:SolidColor color="0x00FFFF"/>
    </s:fill>
  </s:Rect>
</s:Group>

<s:Image source="@Embed(source='my/path/to/img.png')" mask="{imageMask}" />

度过美好的一天。

答案 1 :(得分:1)

适用于 BitmapImage Image BitmapImage 中有自己的 ImageSkin

创建皮肤,设置 skinClass

<s:Image source="@Embed(source='my/path/to/img.png')" 
         skinClass="MyImageSkin"/>

并在 MyImageSkin 内找到 BitmapImage 并设置掩码:

<!--- Primary image display skin part. -->
<s:BitmapImage id="imageDisplay" left="0" top="0" right="0" bottom="0">
    <s:mask>
       <s:Group alpha="0.1">
            <s:Rect width="129" height="123">
                <s:fill>
                    <s:SolidColor color="0x00FFFF"/>
                </s:fill>
            </s:Rect>
        </s:Group>
    </s:mask>
</s:BitmapImage>

答案 2 :(得分:0)

这应该有用。

<s:Image source="@Embed(source='my/path/to/img.png')" >
  <s:mask>
    <s:Group alpha="0.1">
      <s:Rect width="129" height="123">
        <s:fill>
          <s:SolidColor color="0x00FFFF"/>
        </s:fill>
      </s:Rect>
    </s:Group>
  </s:mask>
</s:Image>

s:mask是图像的属性,将使用内部FXG作为掩码。 除非您将maskType =“”属性设置为alpha(对于剪辑,默认属性是可见或不可见),否则alpha不会有任何区别。

相关问题