0

我试图找到一种方法来避免在我的一个应用程序中使用 FXG,但遇到了一个问题,即捕获的位图与原始填充的 FXG 路径不完全相同。最初,假设我有 3 个彼此相邻的形状(您可以想象一个包含 3 个切片的饼图)。我使用下面的“cutImage”函数来捕获填充的位图数据并显示 3 张图片。但是,我们发现每个形状与其他形状相交的一侧有 1 个像素的间隙。不确定是否有任何关系,但捕获的位图与直接显示填充路径完全相同,但“cacheAsBitmap”设置为true。如果我们只显示填充路径并将 cacheAsBitmap 设置为 false,则形状之间没有间隙。

问题:有什么方法可以从路径中捕获 100% 的内容,从而使路径之间没有间隙?

谢谢并恭祝安康

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" >

    <fx:Script>
        <![CDATA[
            import mx.core.IVisualElement;
            import mx.core.IVisualElementContainer;
            import mx.core.UIComponent;
            import mx.events.FlexEvent;
            import mx.graphics.ImageSnapshot;
            import mx.graphics.codec.PNGEncoder;
            import mx.utils.ObjectUtil;


            [Bindable]
            private var cacheAsBitmap_Path:Boolean = false;

            protected function displayImg(event:MouseEvent):void
            {
                this.cutImage(collarGroup, collarImg);
                this.cutImage(zipperGroup, zipperImg);
                this.cutImage(bodyGroup, bodyImg);
                this.img.visible = true;
                this.path.visible = false;
                this.displayLabel.text = "Image";
            }

            private function cutImage(group:Group, image:Image):void
            {
                var bitmap:Bitmap = new Bitmap(new BitmapData(group.width, group.height,true, 0x00000000), PixelSnapping.NEVER, true);
                bitmap.bitmapData.draw(group);
                image.source = bitmap.bitmapData;
            }

            protected function displayPath(event:MouseEvent):void
            {
                this.path.visible = true;
                this.img.visible = false;
                this.cacheBitmapButton.visible = true;
                this.displayLabel.text = "Path : cacheAsBitmap = " + this.cacheAsBitmap_Path;
            }

        ]]>
    </fx:Script>
    <s:Rect width="2000" height="2000">
        <s:fill>
            <s:SolidColor color="0xff0000"/>
        </s:fill>
    </s:Rect>
    <s:Scroller width="1920" height="1000">
        <s:Group>
            <s:Group id="path" visible="true"> 
                <s:Group id="collarGroup" cacheAsBitmap="{cacheAsBitmap_Path}">
                    <s:Path data="M1017.6 331.35 1016.925 334.05Q1020.4527 333.99766 1020.15 336.025 1019.8408 338.05059 1018.45 337.5 1017.0688 336.94766 1016.65 336.925 1016.5514 336.91562 1016.55 340.075 1016.5404 343.24219 1014.85 342.25L1012.25 340.6Q1008.2932 340.85078 1002.9 340.6 1002.426 342.75781 1003.075 343.65 1003.727 344.55703 1005.65 351.575 1006.2492 353.75449 1006.675 357 1007.6303 364.18672 1008.75 375.6 1009.7586 402.7875 1010.125 430.975 1010.39 451.45723 1009.6 479.425 930.64258 455.95742 902.5 447.225 874.35664 438.49453 859.875 428.725 845.39551 418.95293 840.2 402.6 841.5 389.75 842.45 352.3 843.2 323.15 843.2 310.6 842.35 294.3 842.4 287.3 842.5 275.7 845.7 267.05 848.9 258.45 856.3 255.35 858.85 254.3 862.3 253.75 864.15 253.45 867.2 253.05L877.9 251.1Q891.65 248.95 906.85 247.7 955.5 243.7 1000.2 250.55 1028.5 251.85 1080.75 252.55 1117.3 253.05 1138.8 253.05 1157.25 252.15 1175.85 256.65 1197.5 261.85 1201.3 271.1 1201.05 280.05 1200.8 345.8 1200.5 408 1200.25 411.1    1193.71 429.60488 1175.2 437.875 1156.6883 446.15176 1125.55 455.625 1094.4193 465.08672 1028.9 481 1030.3559 444.82168 1032.35 418.85 1037.192 355.6877 1037.825 353.25 1038.4637 350.82031 1040.6 346.4 1042.6629 343.26719 1040.525 343.775 1038.3799 344.2752 1037.225 343.775 1036.0791 343.28086 1036.125 342.05 1036.1668 340.80566 1036.125 340.075 1036.0422 338.59707 1034.2 338.475 1032.3572 338.3584 1027.6 336.85L1027 341.45Q1024.3928 343.16445 1023.5 341.45L1022.75 332.1 1017.6 331.35">
                        <s:fill>
                            <s:SolidColor color="0xf0f000"/>
                        </s:fill>
                    </s:Path>
                </s:Group>
                <s:Group id="zipperGroup" cacheAsBitmap="{cacheAsBitmap_Path}">
                    <s:Path data="M1017.6 331.35 1022.75 332.1 1023.5 341.45Q1024.3928 343.16445 1027 341.45L1027.6 336.85Q1032.3572 338.3584 1034.2 338.475 1036.0422 338.59707 1036.125 340.075 1036.1668 340.80566 1036.125 342.05 1036.0791 343.28086 1037.225 343.775 1038.3799 344.2752 1040.525 343.775 1042.6629 343.26719 1040.6 346.4 1038.4637 350.82031 1037.825 353.25 1037.192 355.6877 1032.35 418.85 1030.3559 444.82168 1028.9 481 1027.942 532.35703 1028.575 604.45 1022.5139 649.55664 1023.75 677.65 1024.666 699.60176 1023.375 725.95 1022.9299 734.81934 1022.525 743.45 1014.8682 905.91426 1018.525 984 1019.4199 1003.0951 1020.175 1018.95 1020.9445 1034.8313 1020.425 1057.05 1019.9063 1079.2572 1019.425 1093.725 1018.9404 1108.2004 1020.25 1140.3L1025.225    1404.9 1022.75 1533.4 1019 1796.6 996.1 1795.3Q1001.2002 1651.6168 1004.95 1585.7 1008.7006 1519.7873 1005.95 1446.7 1003.1898 1373.6053 1003.375 1358.95 1003.7422 1332.3373 1004.15 1303.075 1006.5453 1131.1652 1003.525 808.45 1003.4641 801.98027 1003.4 795.45 1003.0996 764.24102 1004.75 737.65 1004.5584 702.23477 1004.025 679.75 1003.5002 657.26094 1005.075 637.95 1006.6557 618.63555 1007 598.1 1007.3416 577.56914 1007.275 560.75 1007.2055 543.92617 1008.85 501.55 1009.2984 489.95801 1009.6 479.425 1010.39 451.45723 1010.125 430.975 1009.7586 402.7875 1008.75 375.6 1007.6303 364.18672 1006.675 357 1006.2492 353.75449 1005.65 351.575 1003.727 344.55703 1003.075 343.65 1002.426 342.75781 1002.9 340.6 1008.2932 340.85078 1012.25 340.6L1014.85 342.25Q1016.5404 343.24219 1016.55 340.075 1016.5514 336.91562 1016.65 336.925 1017.0688 336.94766 1018.45 337.5 1019.8408 338.05059 1020.15 336.025 1020.4527 333.99766 1016.925 334.05L1017.6 331.35">
                        <s:fill>
                            <s:SolidColor color="0xf0f000"/>
                        </s:fill>
                    </s:Path>
                </s:Group>
                <s:Group id="bodyGroup" cacheAsBitmap="{cacheAsBitmap_Path}">
                    <s:Path  data="M1493.35 552.65Q1505.6 567.35 1530.05 611.35 1552.85 652.45 1560.35 671.2 1567 689.65 1597.5 757.35 1627.85 824.55 1632.85 832.2 1639.5 845.9 1670.85 925.6 1704.4 1010.85 1711.45 1034.75 1719.6 1057.35 1743.75 1133.35 1756.1 1172.05 1770.45             1217.3 1775.45 1232.3 1796 1305.35 1806.6 1342.85 1818.95 1387.35 1828.15 1414.2 1828.95 1422.35 1832.05 1438.45 1838.4 1484.4 1845.95 1539.15 1845.95 1555.4 1846.35 1562.65 1847.3 1574.5 1847.9 1584.55 1846.95 1593.05 1844.6 1614.8 1828.45                1656.9 1830.35 1667.3 1828.35 1676.05 1826.2 1685.15 1819.95 1691.4 1810.3 1696.35 1781.85 1709.9 1751.8 1724.2 1749.4 1725.4 1736.75 1730.6 1718.1 1730.7 1704.5 1730.8 1696.9 1728.9 1691.3 1724.05 1684.4 1707.85 1677.5 1691.65 1679.4 1687.9               1671.6 1684.35 1662.3 1666 1654.3 1650.3 1642.9 1618.9 1627.3 1582.2 1620.7 1565.55 1605.85 1528.15 1604.9 1517.9 1598.1 1493.35 1578.35 1433 1554.55 1360.2 1548.4 1351.8 1543.1 1335.6 1514.5 1266.3 1485.8 1196.85 1478.35 1182.3 1473.3 1172.9  1446.8 1117.05 1421.95 1064.65 1419.35 1060.75 1416.55 1049.8 1414.65 1043.95L1413.35 1040.25 1413.1 1113.65Q1412.6 1189.45 1411.35 1201.3 1412.8 1216.35 1420.65 1312 1427.75 1398.15 1428.85 1405.85 1428.95 1407.75 1434.75 1494.5 1439.85 1571.65   1439.85 1576.4 1439.85 1581.4 1443.05 1648 1445.65 1716.95 1442.85 1739.45 1442.5 1743.95 1442.1 1751.3 1441.6 1757 1440.1 1760.2 1436.5 1767.95 1420.85 1771.95 1404.55 1775.95 1352.45 1782.6 1297.55 1789.2 1284.8 1790.95 1257.65 1793.8 1205.1 1797.75 1149.7 1801.95 1136.25 1801.95 1123.55 1802.15 1078.65 1804.25 1041.5 1806 1038.25 1805.45 1030.45 1806.25 1025.2 1804.35 1019.6 1802.3 1019 1796.6L1022.75 1533.4 1025.225 1404.9 1020.25 1140.3Q1018.9404 1108.2004 1019.425 1093.725 1019.9063 1079.2572 1020.425 1057.05 1020.9445 1034.8313 1020.175 1018.95 1019.4199 1003.0951 1018.525 984 1014.8682 905.91426 1022.525 743.45 1022.9299 734.81934 1023.375 725.95 1024.666 699.60176 1023.75 677.65 1022.5139 649.55664 1028.575       604.45 1027.942 532.35703 1028.9 481 1094.4193 465.08672 1125.55 455.625 1156.6883 446.15176 1175.2 437.875 1193.71 429.60488 1200.25 411.1 1207.4 415.8 1229.55 421.6 1240.9 424.6 1254.3 427.6 1256.3 428.25 1274.45 433.7 1295.65 440.25 1315.2  447.05 1376.9 468.55 1411.8 488.65 1444.4 507.45 1464.95 524.6 1478.4 535.8 1493.35 552.65M859.875 428.725Q874.35664 438.49453 902.5 447.225 930.64258 455.95742 1009.6 479.425 1009.2984 489.95801 1008.85 501.55 1007.2055 543.92617 1007.275 560.75 1007.3416 577.56914 1007 598.1 1006.6557 618.63555 1005.075 637.95 1003.5002 657.26094 1004.025 679.75 1004.5584 702.23477 1004.75 737.65 1003.0996 764.24102 1003.4 795.45 1003.4641 801.98027 1003.525 808.45 1006.5453 1131.1652 1004.15 1303.075 1003.7422 1332.3373 1003.375 1358.95 1003.1898 1373.6053 1005.95 1446.7 1008.7006 1519.7873 1004.95 1585.7 1001.2002 1651.6168 996.1 1795.3L993.5 1799.35Q990.95 1802.1 989.7 1803.95 986.65 1804.6 972.1 1803.6 952.65 1802.15 941.85 1801.35 899.15 1798.1 893.2 1800.95 881.7 1800.15 811.25 1794.4 748.25 1789.25 740.2 1788.95 721.6 1788.5 657.95 1780.95 590.5 1772.95 575.65 1768.45 568.9 1753.7 567.6 1730.45 567.4 1707.45 566.65 1701.45 566.65 1689.2 571.55 1610.2 576.25 1533.65 577.15 1526.4 577.15 1474 577.2 1471 578.3 1419.05 583.65 1389.8 584.45 1378 586.55 1357.35 588.95 1333.35 589.85 1322.45 593.6 1277.15 592.65 1228.8 593.2 1220 595.65 1167.25 597.5 1127.35 598.65 1121.8 599.3 1112.7 599.3 1081 599.15 1050 599.15 1047.75 593.85 1063.35 563.7 1127.8 535.35 1188.4 534.65 1192.8 530.9 1202.05 495.65 1286 460.25 1372.4 450.6 1407.35 443.35 1428.6 428.9 1469.95 416.3 1508.9 406.1 1555.4 402.4 1564.95 385.9 1604.65 373.8 1633.8 372.1 1640.4 368.85 1645.65 365.1 1654.75 362.95 1659.9 358.8 1670.45 350.9 1689.35 342.1 1694.9 342.1 1704.1 340.55 1708.65 339.7 1711.1 335.6 1717.45 333.2 1721.2 330.05 1728.15 326.95 1734.9 325.6 1736.95 309.1 1740.9 291.35 1738.1 274.65 1734.2 269.1 1733.95  261.6 1731.25 234.7 1717.1 204.35 1701.1 204.05 1700.95 195.9 1697.9 192.85 1687.75 190.6 1680.15 191.05 1667.4 184.3 1647.15 180.1 1633.8 172.25 1608.65 172.55 1596.4 171.7 1576.8 174.95 1535.05 178.65 1486.95 185.55 1446.35 193.5 1408.8 220.3 1312.4 246.55 1218 252.05 1205.8 310.55 1020.25 317.05 1004.75 322.9 983.45 348.85 912.15 377.5 833.3 385.1 823.7 389.35 812.4 413.55 757.5 437.35 703.65 438.6 700.65 441.3 691.45 463.3 646.7 487.2 598 495.1 590.1 502.6 576.6 516.55 557 530.45 537.4 533.1 536.65 537.9 529.75 566.65 507.95 593.35 487.65 604.65 481.1 613.9 473.85 670.15 452.4 720.05 433.4 737.15 428.6 749.95 424.55 793.55 413.75 834.5 403.55 840.2 402.6 845.39551 418.95293 859.875 428.725">
                        <s:fill>
                            <s:SolidColor color="0xf0f000"/>
                        </s:fill>
                    </s:Path>
                </s:Group>
            </s:Group>   
            <s:Group id="img">
                <s:Image id="collarImg"/>
                <s:Image id="zipperImg"/>
                <s:Image id="bodyImg"/>
            </s:Group>
        </s:Group>
    </s:Scroller>   
    <s:HGroup width="100%" horizontalAlign="center" verticalAlign="middle" y="200">
        <s:Button id="displayImgButton" x="200" click="displayImg(event)" visible="true" label="Display Image"/>
        <s:Button id="displayPathButton" x="400"  click="displayPath(event)" visible="true" label="Display Path"/>
        <s:Button id="cacheBitmapButton" label="Change cacheAsBitmap" click="cacheAsBitmap_Path = !cacheAsBitmap_Path; this.displayLabel.text = 'Path : cacheAsBitmap = ' + this.cacheAsBitmap_Path;"/>
        <s:Label id="displayLabel"/>
    </s:HGroup>

</s:WindowedApplication>
4

1 回答 1

0

尝试使用矩阵将位图从其注册点移动 1 像素。您只能在注册点的右侧和下方进行捕获,因此如果图形的任何部分落在它的另一侧,它将被切断。查看此链接以获取演示此技术的代码http://flexdiary.blogspot.com/2009/12/riadventure-inspiration.html

于 2012-02-13T13:28:49.237 回答