WritableBitmapEx 一瞥

今天在蓝色上看到一篇介绍WritableBitmapEx的贴子(是开源项目),项目地址:http://writeablebitmapex.codeplex.com/

对SL的WritableBitmap做了一些扩展,可以方便的绘制一些基本几何形状,示例代码如下:

代码
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace WriteableBitmapExDemo
{
    
public partial class MainPage : UserControl
    {
        
public MainPage()
        {
            InitializeComponent();

            
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        }

        
void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            WriteableBitmap _wb 
= new WriteableBitmap(512512);//新建一个512px * 512px的可写位图
            this.ImgDemo.Source = _wb;

            _wb.Clear(Colors.White);
//填充背景色为白色

            
//从(50,0)到(0,50)划一根线,颜色为绿色
            _wb.DrawLine(500050, Colors.Magenta);

            
//从(100, 100)到(50,187)再到(150,187)划一个黑色三角形
            _wb.DrawTriangle(10010050187150187, Colors.Black);

            
//从(50, 50) 到(100,100)划一个红色的矩形
            _wb.DrawRectangle(5050100100, Colors.Red);

            
//从(200,200)为中心,划一个横轴为100,竖轴为50的椭圆
            _wb.DrawEllipseCentered(20020010050, Colors.Blue);

            
//划一个多边形 P1(10, 5), P2(20, 40), P3(30, 30) and P4(7, 8)
            int[] p = new int[] { 1052040303078105 };
            _wb.DrawPolyline(p, Colors.Green);

            
//Present the WriteableBitmap!
            _wb.Invalidate();//实际测试下来,好象不加这一行也可以运行

        }

    }
}

官方还给出二个演示的地址:

http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/ShapeSample/TestPage.html

http://dl.dropbox.com/u/2681028/CodeplexData/WriteableBitmapEx/BlitSample/TestPage.html

理论上讲,只要精通图形算法再加上一点艺术细胞,直接用cs代码画出一个MM来是可行的 :)

作者:菩提树下的杨过
出处:http://yjmyzz.cnblogs.com
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/yjmyzz/p/1619377.html