【WIN10】WIN2D——基本圖形的繪製
2015-12-19 17:54
387 查看
DEMO下載地址:http://yunpan.cn/c3iNuHFFAcr8h (提取码:8e48)
先看一個截圖:
繪製了一些基本形狀。
DEMO的繪製代碼都非常簡單,不想在博客裡細說了,看代碼更為清晰些。
可能繪製扇形的代碼有些麻煩些。
微軟是使用鐘錶的轉動方向(順時針)作為弧度運轉方向的,所以角度30度,是會在x座標下的,而不是通常的在x座標上面。
帖一下畫鐘錶的代碼,是非常簡單的:
因為今天只寫了這麼一個例子,就先發一個了。
後面再一一補上。
先看一個截圖:
繪製了一些基本形狀。
DEMO的繪製代碼都非常簡單,不想在博客裡細說了,看代碼更為清晰些。
可能繪製扇形的代碼有些麻煩些。
微軟是使用鐘錶的轉動方向(順時針)作為弧度運轉方向的,所以角度30度,是會在x座標下的,而不是通常的在x座標上面。
帖一下畫鐘錶的代碼,是非常簡單的:
private void clock_Draw(CanvasControl sender, CanvasDrawEventArgs args) { float radius = (float)sender.ActualWidth / 2 - 4; Vector2 center = new Vector2((float)sender.ActualWidth / 2, (float)sender.ActualWidth / 2); for (int i = 0; i < 60; ++i) { int borderSize = 1; Vector2 begin = new Vector2(radius + center.X - 3, center.Y); Vector2 end = new Vector2(radius + center.X, center.Y); if (i % 15 == 0) { borderSize = 4; begin = new Vector2(center.X + radius - 15, center.Y); } else if (i % 5 == 0) { borderSize = 2; begin = new Vector2(radius + center.X - 10, center.Y); } args.DrawingSession.Transform = Matrix3x2.CreateRotation(TimeValue2Radion(i, 60), center); args.DrawingSession.DrawLine(begin, end, Color.FromArgb(255, 255, 255, 255), borderSize); } args.DrawingSession.DrawCircle(center, radius, Color.FromArgb(255, 255, 255, 255), 2); // 結點處是圓,指向處為三角 CanvasStrokeStyle lineStyle = new CanvasStrokeStyle(); lineStyle.StartCap = CanvasCapStyle.Round; lineStyle.EndCap = CanvasCapStyle.Triangle; // 時針 float hours = DateTime.Now.Hour % 12 + DateTime.Now.Minute / 60.0f + DateTime.Now.Second / 60.0f / 24.0f; // 12小時制 float intervalHours = hours - 3.0f; // 3點是0度 float hourRadian = TimeValue2Radion(intervalHours, 12); args.DrawingSession.Transform = Matrix3x2.CreateRotation(hourRadian, center); args.DrawingSession.DrawLine(center, new Vector2(center.X + 80, center.Y), Color.FromArgb(255, 255, 255, 255), 5, lineStyle); // 分針 float minutes = DateTime.Now.Minute+ DateTime.Now.Second / 60.0f; float intervalMinutes = minutes - 15; // 15分钟是0度 float minuteRadian = TimeValue2Radion(intervalMinutes, 60); args.DrawingSession.Transform = Matrix3x2.CreateRotation(minuteRadian, center); args.DrawingSession.DrawLine(center, new Vector2(center.X + 100, center.Y), Color.FromArgb(255, 255, 255, 255), 2, lineStyle); // 秒針 float seconds = DateTime.Now.Second; float intervalSeconds = seconds - 15; // 15秒是0度 float secondRadian = TimeValue2Radion(intervalSeconds, 60); args.DrawingSession.Transform = Matrix3x2.CreateRotation(secondRadian, center); args.DrawingSession.DrawLine(center, new Vector2(center.X + 120, center.Y), Color.FromArgb(255, 255, 255, 255)); } private float TimeValue2Radion(float intervalTime, int total) { return intervalTime / total * 360 * (float)Math.PI / 180; }
因為今天只寫了這麼一個例子,就先發一個了。
後面再一一補上。
相关文章推荐
- 哇哈哈~申请第一天。
- PAT乙级 打印沙漏(20)
- 模块化程序设计函数与方法
- 浅析人脸检测之Haar分类器方法
- 汇编语言将回车键的问题和集成开发的问题
- ansible高级用法
- 什么是spring,谈谈你对spring的理解
- 动态设置Layout的宽高值
- spring与Hibernate的整合(以及spring的声明式事务处理)
- 局域网内部访问问题
- ansible高级用法
- JavaScript生成随机字符
- js中的KeyCode码
- c#中ref与out的区别
- 关于默认构造函数的一点总结
- 龙芯1B,龙芯1C系列VxWorks操作系统BSP调试完成
- 自定义通知的方法
- 1009. Triple Inversions (35)
- linux命令集锦之curl
- Android点滴---ViewHolder通用,优雅写法