微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight 引路蜂二维图形库示例:材质画刷

除了单色,渐变画刷外,也可以使用图像作为模式(Pattern)画刷来填充图形。

下面的例子使用两个PNG图像来填充图形。

private void Patterns()
{
    TextureBrush brush1;
    TextureBrush brush2;
    TextureBrush brush3;
 
    AffineTransform matrix1 = new AffineTransform();
    AffineTransform matrix2 = new AffineTransform();
 
    BitmapImage img = new BitmapImage();
    img.CreateOptions = BitmapCreateOptions.None;
    string path = "/SilverlightGraphics2DDemo;component/brick.png";
    Stream s = Application.GetResourceStream
        (new Uri(path,UriKind.Relative)).Stream;
    img.SetSource(s);
    WriteableBitmap writeableBitmap = new WriteableBitmap(img);
    brush1 = new TextureBrush(writeableBitmap.Pixels,img.PixelWidth,img.PixelHeight);
    path = "/SilverlightGraphics2DDemo;component/bird.png";
    s = Application.GetResourceStream(new Uri(path,UriKind.Relative)).Stream;
    img.SetSource(s);
    writeableBitmap = new WriteableBitmap(img);
    brush2 = new TextureBrush(writeableBitmap.Pixels,img.PixelHeight);
    brush3 = new TextureBrush(writeableBitmap.Pixels,img.PixelHeight,127);
    matrix2.Translate(50,50);
    graphics2D.Clear(Color.White);
    graphics2D.AffineTransform = (matrix1);
    graphics2D.FillRectangle(brush1,new Rectangle(20,50,100,100));
    graphics2D.Filloval(brush2,10,80,80);
    graphics2D.AffineTransform = (matrix2);
    graphics2D.Filloval(brush3,80);
 
}

这个例子所用的brick.png 和bird.png,brush3是半透明画刷。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐