底层绘图代码

  • 格式:txt
  • 大小:20.77 KB
  • 文档页数:8
if(y < 0 || y >= h) continue;
unsigned char *py = p[y];
//绘制抗锯齿的直线(Bitmap必须为32位位图,边界可以溢出)
//---------------------------------------------------------------------------
void __fastcall mDrawLineA(unsigned char **p, //Bitmap的行指针
//---------------------------------------------------------------------------
bool __fastcall mGetDotLineDis(int x1, int y1, int x2, int y2, int x, int y, int r)
int r3 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
if(r1 <= r) return true;
if(r2 <= r) return true;
if(r3 <= r) return false;
float botton = y2;
if(y2 < y1)
{
top = y2;
botton = y1;
}
float dx, dy, r, c;
int x, y, m, n;
float y21 = y2 - y1;
//---------------------------------------------------------------------------
#pragma hdrstop
#include "UnitDrawFunc.h"
#include "UnitMain.h"
//---------------------------------------------------------------------------
float x21 = x2 - x1;
float xyk = x21 / y21;
for(dy = top; dy <= botton; dy += u)
{
if(dy < 0)
{
dy == 0;
continue;
py[x4 ] = bb;
py[x4 + 1] = gg;
py[x4 + 2] = rr;
}
}
}
}
//Y方向较大的直线
else
{
float top = y1;
int R, //颜色--红
int G, //颜色--绿
int B, //颜色--蓝
float y1 = (y - ry) * cos(ra) + (x - rx) * sin(ra);
x = x1 + rx;
y = y1 + ry;
}
//---------------------------------------------------------------------------
float c = 1.0 - r;
if(c <= 0) continue;
float u = 1.0 - c;
int x4 = x * 4;
int rr = R * c + u * py[x4 + 2];
int gg = G * c + u * py[x4 + 1];
{
r = r * r;
while(1)
{
int r1 = (x - x1) * (x - x1) + (y - y1) * (y - y1);
int r2 = (x - x2) * (x - x2) + (y - y2) * (y - y2);
{
float dx, dy, r, c;
int x, y, m, n;
dx = (x1 + x2) / 2.0;
dy = (y1 + y2) / 2.0;
for(y = dy - 1; y <= dy + 1; y++)
{
if(y < 0 || y >= h) return;
float u) //步进
{
//计算旋转后的坐标
mRotateF(rx, ry, ra, x1, y1);
mRotateF(rx, ry, ra, x2, y2);
//一个点
if(fabs(y2 - y1) <= 1.0 && fabs(x2 - x1) <= 1.0)
int bb = B * c + u * py[x4 ];
py[x4 ] = bb;
py[x4 + 1] = gg;
py[x4 + 2] = rr;
}
}
}
//X方向较大的直线
else if(fabs(x2 - x1) >= fabs(y2 - y1))
if(r1 > r2)
{
x1 = (x1 + x2) / 2;
y1 = (y1 + y2) / 2;
}
else
{
x2 = (x1 + x2) / 2;
y2 = (y1 + y2) / 2;
}
float y1, //起点y
float x2, //终点x
float y2, //终点y
float rx, //旋转中心点x
float ry, //旋转中心点y
float ra, //旋转角度(度)
int x4 = x * 4;
int rr = R * c + u * py[x4 + 2];
int gg = G * c + u * py[x4 + 1];
int bb = B * c + u * py[x4 ];
float y21 = y2 - y1;
float x21 = x2 - x1;
float yxk = y21 / x21;
for(dx = left; dx <= right; dx += u)
{
if(dx < 0)
{
}
}
//---------------------------------------------------------------------------
//计算某点已另一点为圆心旋转某角度后的新坐标
//---------------------------------------------------------------------------
dx == 0;
continue;
}
if(dx >= w) return;
dy = yxk * (dx - x1) + y1;
if(dy < 0 || dy >= h) continue;
for(y = dy - 1; y <= dy + 1; y++)
{
if(y < 0 || y >= h) continue;
unsigned char *py = p[y];
for(x = dx - 1; x <= dx + 1; x++)
{
if(x < 0 || x >= w) continue;
}
if(dy >= h) return;
dx = (dy - y1) * xyk + x1;
if(dx < 0 || dx >= w) continue;
for(y = dy - 1; y <= dy + 1; y++)
{
#pragma package(smart_init)
//---------------------------------------------------------------------------
//计算点到线段的距离,点x, y到线段x1, y1, x2, y2的距离,小于r返回true,否则返回false
int w, //Bitmap的width
int h, //Bitmap的Height
float x1, //起点x
void __fastcall mRotateF(float rx, float ry, float ra, float &x, float &y)
{
if(ra == 0) return;
ra = 0.0 - ra * M_PI / 180.0;
float x1 = (x - rx) * cos(ra) - (y - ry) * sin(ra);
r = sqrt((x - dx) * (x - dx) + (y - dy) * (y - dy));
float c = 1.0 - r;
if(c <= 0) continue;
float u = 1.0 - c;

下载文档原格式

  / 8