如何在C ++中的图像中垂直绘制线(斜线)? [英] How to draw line ( slanting line ) vertically in an image in c++?

查看:331
本文介绍了如何在C ++中的图像中垂直绘制线(斜线)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

如何垂直绘制线(斜线)???

对于Ex:
考虑X1 = 100,Y1 = 80;并且X2 = 100,Y2 = 185;

所以这是针对直线

Hello,

How to draw line ( slanting line ) vertically ???

For Ex :
Consider X1 = 100, Y1 = 80; And X2=100, Y2 = 185;

So This is for Straight LINE

for(nRow = Y1; nRow < Y2; nRow++)
{
  for(nCol = X1; nCol < X2; nCol++)
  {
     nPixPos = nRow*nEffectiveWidth+nCol*3; 

     Image[nPixPos] = 0 ;
     Image[nPixPos+1] = 0 ;
     Image[nPixPos+2] = 0 ;
  }
}



如果我想为EX绘制线:X1 = 100,Y1 = 80且 X2 = 115 ,Y2 = 185

上面的坐标如何绘制斜线-如何使用for循环然后???



If i want to draw Line for EX :X1 = 100 , Y1 = 80 and X2 = 115 , Y2 = 185

HOW TO DRAW Slanting Line for the above CO-ORDINATES - how to use for loop then ???

推荐答案

哦,男孩!在20年间我还没有实现其中之一?

有很多方法可以做到:有些简单,有些更好. Wiki有一个列表: http://en.wikipedia.org/wiki/Line_drawing_algorithm [
Oh boy! I haven''t implemented one of those in what...twenty years?

There are a lot of ways to do it: some simple, and some much, much better. Wiki has a list: http://en.wikipedia.org/wiki/Line_drawing_algorithm[^] - pick one you like and off you go!

(But don''t expect them to look as good as the standard Windows line drawing functions unless you put in a lot of work. Look up antialiasing while you are at it.)


这篇关于如何在C ++中的图像中垂直绘制线(斜线)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆