Bresenham算法画线
作者:互联网
原文链接:http://www.cnblogs.com/WilliamJiang/archive/2012/07/18/2597948.html
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing;namespace BresenhamLine.Util { class DrawLine { [System.Runtime.InteropServices.DllImport("gdi32.dll")] internal static extern bool SetPixel(IntPtr hdc, int x, int y, uint color); public void MyDrawLine(Graphics g, Point pStart, Point pEnd) { int x, y, dx, dy, m; float e; x =pStart.X; y =pStart.Y; dx = pEnd.X - pStart.X; dy = pEnd.Y - pStart.Y; m = dy / dx; e = m - 0.5f; Pen pen = new Pen(Color.Red,1); IntPtr hdc = g.GetHdc(); for (int i = 1; i < dx; i++) { SetPixel(hdc, x, y, 0xffff0000); while (e > 0) { y = y + 1; e = e - 1; } x = x + 1; e = e + m; } g.ReleaseHdc(hdc); } } }
转载于:https://www.cnblogs.com/WilliamJiang/archive/2012/07/18/2597948.html
标签:pStart,int,Bresenham,画线,System,算法,hdc,dx,using 来源: https://blog.csdn.net/weixin_30556959/article/details/99614405