MSDN 教學視頻 WPF10(圖片剪下)

來源:互聯網
上載者:User
圖片剪下

今天我要實現在圖片上剪下我們想要的圖形。

首先建立一個WPF應用程式。

我們在圖片上實現剪下,那一定要用到Image控制項了。用到Image的剪下屬性Clip。

下面我們先截一個橢圓。

<Grid>        <Image Source="tulips.jpg" Width="300" Height="200" Stretch="Fill">            <Image.Clip>                <EllipseGeometry Center="150,100"  RadiusX="120" RadiusY="90"/>            </Image.Clip>        </Image>    </Grid>

效果

 

image.Clip下有6個可畫的圖形。
1、CombinedGeometry  表示由兩個 System.Windows.Media.Geometry 對象組合定義的二維幾何形狀。

2、GeometryGroup 表示由其他 System.Windows.Media.Geometry 對象組成的複合幾何圖形。

3、LineGeometry 表示線條的幾何圖形。

4、PathGeometry

指定用於產生此動畫輸出值的幾何圖形。這是一個依賴項屬性。

傳回值:
用於產生此動畫輸出值的路徑。預設值為 null。

5、RectangleGeometry  描述二維矩形。

6、StreamGeometry

定義幾何形狀,並使用 System.Windows.Media.StreamGeometryContext 進行描述。此幾何圖形是 System.Windows.Media.PathGeometry 的輕量替代圖形:它不支援資料繫結、動畫或修改。

下面我們用PathGeomitry來畫。

 <Image Source="tulips.jpg" Width="300" Height="200" Stretch="Fill">            <Image.Clip>                <PathGeometry>                    <PathGeometry.Figures>                        <PathFigureCollection>                            <PathFigure StartPoint="150,30" IsClosed="True">                                <LineSegment Point="60,180" />                                <LineSegment Point="240,180"/>                            </PathFigure>                        </PathFigureCollection>                    </PathGeometry.Figures>                </PathGeometry>            </Image.Clip>        </Image>

這裡用到IsClosed=”True”是圖形封閉起來。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.