使用wpf制作博客园logo

闲的JJ疼,用 xaml画了个博客园的logo,Metro风格的。

xaml代码

            <Grid Width="100" Height="100" Background="White"
                  x:Name="gridLogo">
                <Ellipse Margin="5" Fill="Blue"/>
                <Path Stroke="White" StrokeThickness="12" 
                              StrokeStartLineCap="Round"
                              StrokeEndLineCap="Round">
                    <Path.Data>
                        <PathGeometry>
                            <PathFigureCollection>
                                <PathFigure StartPoint="38,24">
                                    <PathFigure.Segments>
                                        <ArcSegment Point="78,62"
                                                        Size="40,40"
                                                        SweepDirection="Clockwise">
                                        </ArcSegment>
                                    </PathFigure.Segments>
                                </PathFigure>
                                <PathFigure StartPoint="33,45">
                                    <PathFigure.Segments>
                                        <ArcSegment Point="59,69"
                                                        Size="25,25"
                                                        SweepDirection="Clockwise">
                                        </ArcSegment>
                                    </PathFigure.Segments>
                                </PathFigure>
                            </PathFigureCollection>
                        </PathGeometry>
                    </Path.Data>
                </Path>
                <Ellipse Margin="24,40,0,0" Width="18" Height="18"
                                 Fill="White"
                                 HorizontalAlignment="Left"/>
            </Grid>

截图代码

            WriteableBitmap bitmap = new WriteableBitmap(this.gridLogo, new MatrixTransform());
            //bitmap.Invalidate();
            using (MemoryStream memoryStream = new MemoryStream())
            {
                bitmap.SaveJpeg(memoryStream, bitmap.PixelWidth, bitmap.PixelHeight, 0, 100);
                memoryStream.Seek(0, SeekOrigin.Begin);
                new Microsoft.Xna.Framework.Media.MediaLibrary().SavePicture("cnblogs.logo", memoryStream);
            }

因为即使是把Grid的属性Background设置为Transparent,也没办法使所截的图片透明,所以将其设置为了白色,WriteableBitmap应该可以处理,只是我不知道该怎么做,会的请告知,thx (找到原因了,jpg格式不支持透明,不知道能不能保存为png格式)

logo效果

未设置Background属性和将Background属性设置为透明,都是默认背景颜色(黑色)

将背景设置为白色

cnblogsLogo.rar

原文地址:https://www.cnblogs.com/grj1046/p/3449443.html