硬汉嵌入式论坛

 找回密码
 立即注册
查看: 2520|回复: 1
收起左侧

[LTDC] LCDH7_DrawLine的BUG

[复制链接]

10

主题

140

回帖

170

积分

初级会员

积分
170
发表于 2019-4-23 16:51:13 | 显示全部楼层 |阅读模式

如图所示,画的直线在第2点开始会向左和向下各偏移一个像素。
QQ五笔截图未命名.png

下面的感觉更好用。
void LCD_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
        uint16_t t;
        int xerr = 0, yerr = 0, delta_x, delta_y, distance;
        int incx, incy, uRow, uCol;

        delta_x = x2 - x1; //计算坐标增量
        delta_y = y2 - y1;
        uRow = x1;
        uCol = y1;

        if (delta_x > 0)
        {
                incx = 1; //设置单步方向
        }
        else if (delta_x == 0)
        {
                incx = 0; //垂直线
        }
        else
        {
                incx = -1;
                delta_x = -delta_x;
        }

        if (delta_y > 0)
        {
                incy = 1;
        }
        else if (delta_y == 0)
        {
                incy = 0; //水平线
        }
        else
        {
                incy = -1;
                delta_y = -delta_y;
        }
        //选取基本增量坐标轴
        if ( delta_x > delta_y)
        {
                distance = delta_x;
        }
        else
        {
                distance = delta_y;
        }

        for (t = 0; t <= distance + 1; t++)
        {
                LCD_SetPixel(uRow, uCol, color); //画点
                xerr += delta_x;
                yerr += delta_y;
                if (xerr > distance)
                {
                        xerr -= distance;
                        uRow += incx;
                }
                if (yerr > distance)
                {
                        yerr -= distance;
                        uCol += incy;
                }
        }
}

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107128
QQ
发表于 2019-4-23 18:05:45 | 显示全部楼层
谢谢楼主指出。

这个问题前几天坛友@王海靖指出了,仅需把 x += tx 放在  LCDH7_PutPixel ( x , y , _usColor) 前面即可。
http://www.armbbs.cn/forum.php?mod=viewthread&tid=4048

QQ截图20190423180513.jpg





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-19 20:32 , Processed in 0.163305 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表