绘制一个半透明的星形,但是进行缩放变大变大操作时,会有两条线重复绘制导治半透明产生两条线是填充问题,有什么方法可以改进吗?

0

下面是问题代码:?




// EasyX 简单缓冲区半透明画点,让你的绘图支持任意的透明度,达到让大家推波推润的效果。
// 2023 - 4 - 7 
// 作者:葉澜郡
// QQ:2250395955
#define WINVER 0x0A00
#define _WIN32_WINNT 0x0A00
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
#include <ShellScalingApi.h>		// 引用头文件
#pragma comment(lib, "Shcore.lib")	// 链接库文件
// 打开缓冲区。
DWORD* g_pBuf11;
// 进行前景色和背景色半透明计算。
COLORREF  Alphargb1(int r1, int g1, int b1, int r2, int g2, int b2, int alp)
{
	COLORREF rgb1 = RGB
	(
		((((r1 * alp)) + ((100 - alp) * r2)) * 0.01),
		((((g1 * alp)) + ((100 - alp) * g2)) * 0.01),
		((((b1 * alp)) + ((100 - alp) * b2)) * 0.01)
	);
	return rgb1;
}
// 显示缓冲区指针,并读取坐标上的颜色值。
COLORREF fast_getpixel1(int x, int y, int WIDTH) { COLORREF c = g_pBuf11[y * WIDTH + x]; return BGR(c); }

// 快速缓冲区半透明画点函数 2
void putpixel11(DWORD* g_pBuf, int x, int y, COLORREF c)
{
	int xxx = getwidth(), ax = (y * xxx + x), WIDTH = getwidth(), puti = abs(y * WIDTH + x);

	if (puti <= 1) { puti == 5; }
	if (puti <= (getwidth() * getheight())) { puti - 5; }
	COLORREF bj, bjys = getbkcolor();

	//printf("%d-%d-%d",rh,gh,bh);
	// 读取背景上的颜色点。
	bj = fast_getpixel1(x, y, xxx);
	//if (bj != WHITE) bj = fast_getpixel(x, y, xxx);
	// 声明定义背景颜色和绘图的颜色。
	int r2 = GetRValue(c), g2 = GetGValue(c), b2 = GetBValue(c), r1 = GetRValue(bj), g1 = GetGValue(bj), b1 = GetBValue(bj);
	// 获取背景颜色和绘图颜色,并进行透明混合计算和,排除不是透明的部分。
	COLORREF bj1 = BGR(r1, g1, b1);
	// 排除非透明区域的颜色,只混合有颜色的区域。

	if (bjys == bj) { g_pBuf[puti] = BGR(c); }
	if (bj != bjys) { g_pBuf[puti] = BGR(Alphargb1(r2, g2, b2, r1, g1, b1, 10)); }

}
int cf1 = 0, cf2 = 0;
// 中点画圆法,转为星星形状
void Circle_Midpoint55(int x, int y, int r, int color, int temp)
{
	DWORD* pu = GetImageBuffer();
	int tx = 0, ty = r, d = 1 - r, d1 = 0;
	while (tx <= ty)
	{
		if (temp == 1)
		{
			putpixel11(pu, x + ty, y + tx, color); putpixel11(pu, x + tx, y + ty, color);																		d1 = 0;
			int g = 1;

			if (y + ty != cf1)
			{
				for (int i = (x + tx); i <= (x + r) - 1; i++) { putpixel11(pu, (x + tx) + d1, y + ty - 1, color);	d1++; }		d1 = 0;//
			}
			cf1 = y + ty;

			if (y + tx != cf2)
			{
				for (int i = (x + ty); i <= (x + r) - 1; i++) { putpixel11(pu, (x + ty) + d1, y + tx - 1, color);	d1++; }///
			}
			cf2 = y + tx;
		}
		if (temp == 2)
		{
			putpixel11(pu, x - ty, y + tx, color); putpixel11(pu, x - tx, y + ty, color);						d1 = 0;

			if (y + tx != cf1)
			{
				for (int i = (x - ty); i >= (x - r); i--) { putpixel11(pu, (x - ty) + d1, y + tx - 1, color);	d1--; }		d1 = 0;///
			}
			cf1 = y + x;

			if (y + ty != cf2)
			{
				for (int i = (x - tx); i >= (x - r); i--) { putpixel11(pu, (x - tx) + d1, y + ty - 1, color);	d1--; }//
			}
			cf2 = y + ty;
		}
		if (temp == 3)
		{
			putpixel11(pu, x - ty, y - tx, color); putpixel11(pu, x - tx, y - ty, color);						d1 = 0;
			if (y - tx != cf1)
			{
				for (int i = (x - ty); i >= (x - r); i--) { putpixel11(pu, (x - ty) + d1, y - tx, color);	d1--; }		d1 = 0;
			}
			cf1 = y - tx;

			if (y - ty != cf2)
			{
				for (int i = (x - tx); i >= (x - r); i--) { putpixel11(pu, (x - tx) + d1, y - ty, color);	d1--; }
			}
			cf2 = y - ty;
		}
		if (temp == 4)
		{
			putpixel11(pu, x + tx, y - ty, color); putpixel11(pu, x + ty, y - tx, color);						d1 = 0;

			if (y - ty != cf1)
			{
				for (int i = (x + tx); i <= (x + r) - 1; i++) { putpixel11(pu, (x + tx) + d1, y - ty, color);	d1++; }		d1 = 0;
			}
			cf1 = y - ty;
			if (y - tx != cf2)
			{
				for (int i = (x + ty); i <= (x + r) - 1; i++) { putpixel11(pu, (x + ty) + d1, y - tx, color);	d1++; }
			}
			cf2 = y - tx;
		}

		if (d < 0)d += 2 * tx + 3; else d += 2 * (tx - ty) + 5, ty--;
		tx++;
	}
}
void star1(int x, int y, int lie = NULL)
{
	int x1 = x - lie, y1 = y - lie; int x2 = x + lie, y2 = y - lie; int x3 = x + lie, y3 = y + lie; int x4 = x - lie, y4 = y + lie;
	Circle_Midpoint55(x1, y1, lie, RED, 1); Circle_Midpoint55(x2, y2, lie, BLUE, 2);
	Circle_Midpoint55(x3, y3, lie, WHITE, 3); Circle_Midpoint55(x4, y4, lie, BLACK, 4);
}
// 画支持透明的矩形。
void rec(int x1, int y1, int x2, int y2, COLORREF c)
{// 获取绘图区宽度。
	int  WIDTH = getwidth();	g_pBuf11 = GetImageBuffer();
	for (int i = y1; i < y1 + (y2 - y1); i++)for (int j = x1; j < x1 + (x2 - x1); j++)putpixel11(g_pBuf11, j, i, c);
}
int R[] =
{
7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,9,10,10,11,11,11,12,12,12,14,14,14,14,15,15,15,16,15,16,15,15,16,16,16,18,19,19,19,19,19,20,21,22,22,22,22,23,23,24,24,24,27,27,28,29,32,32,33,33,34,
34,36,36,36,37,38,39,42,43,44,45,45,46,47,48,50,51,54,55,56,61,64,66,67,70,70,69,70,74,77,78,83,86,90,94,99,103,106,107,109,112,114,116,126,141,146,138,126,123,123,129,132,130,123,119,116,115,116,
118,118,117,116,114,114,112,110,106,101,96,93,89,84,79,76,74,70,68,66,65,64,64,63,60,58,55,51,48,43,43,43,42,41,40,39,38,37,38,38,37,36,36,33,30,28,28,27,27,28,27,24,23,21,21,19,19,19,19,18,18,17,
17,17,16,15,14,13,13,14,15,15,15,15,15,14,14,14,14,13,13,13,13,13,13,13,12,10,9,6,5,5,6,6,7,7,7,7,7,8,8,8,8,9,8,7,7,7,8,9,10,9,9,9,9,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,12,12,12,12,13,12,11,11,11,11,12,12,12,13,13,13,13,13,13,13,13,12,12,9,9,9,9,9,9,9,9,10,
10,10,11,12,12,12,13,12,12,12,12,12,12,13,13,13,13,13,13,13,13,14,14,15,15,15,15,15,15,15,15,15,15,15,15,18,18,19,19,19,19,20,20,21,21,21,22,22,22,22,22,22,22,23,23,24,25,25,26,27,28,29,30,30,32,34,33,
33,37,37,34,36,35,35,34,32,32,32,32,31,30,30,29,28,28,28,28,27,27,27,27,27,27,27,26,26,25,25,24,22,22,22,22,22,22,22,22,22,22,22,22,22,22,21,21,20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,22,23,23,23,
23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,23,24,24,24,24,21,22,23,24,23,22,22,23,23,23,23,23,23,23,23,23,26,26,26,26,26,26,26,26,26,26,26,27,27,27,27,27,24,24,24,24,24,24,24,24,24,24,24,
24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,28,28,28,27,27,27,27,27,27,27,27,27,27,27,27,26,25,24,25,25,26,28,28,28,30,29,29,29,29,29,30,
29,30,31,32,33,35,36,36,37,37,36,36,36,37,37,36,35,36,36,37,38,39,40,42,43,43,43,46,46,47,47,48,48,49,49,50,50,51,52,52,52,53,53,53,54,54,55,56,56,56,57,58,59,61,62,63,63,65,66,67,67,68,69,69,70,73,74,74,
74,73,73,75,76,74,72,73,77,81,84,83,82,85,84,83,82,82,81,80,79,79,78,77,77,75,75,75,75,74,74,74,75,75,75,76,76,75,75,75,75,75,76,78,78,75,79,80,79,79,81,80,79,84,82,80,80,80,76,71,70,69,69,69,67,65,64,64,
64,63,61,60,61,59,58,57,57,58,60,62,62,62,62,62,61,62,61,62,62,64,64,65,65,65,65,64,64,64,64,64,64,63,64,63,65,68,69,75,85,98,123,146,152,143,128,105,86,77,72,70,69,66,65,65,64,62,64,66,65,64,62,62,62,64,
63,62,61,61,61,61,60,56,55,54,54,53,53,54,54,54,54,54,54,53,53,53,53,52,52,51,51,50,50,50,50,49,49,49,49,47,47,47,47,49,49,49,49,48,48,48,48,51,50,50,51,51,49,49,51,50,51,51,50,48,50,50,47,46,45,45,45,44,
44,44,43,42,42,42,41,41,40,40,40,40,40,40,40,40,40,40,39,39,39,40,40,40,41,41,41,41,41,41,41,41,41,40,40,40,40,39,39,39,39,39,39,38,38,37,37,37,37,38,38,38,38,38,38,38,37,36,36,36,36,36,36,36,36,36,36,36,
36,36,36,36,36,36,36,36,36,36,36,36,36,36,36,35,35,36,35,33,33,32,32,32,32,33,33,33,33,35,35,34,34,34,35,35,35,35,35,35,35,35,35,35,36,36,36,36,36,36,37,37,37,37,37,37,37,37,37,37,37,37,37,36,37,36,36, };
int G[] =
{
4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,7,7,8,8,8,9,9,9,12,12,12,12,13,13,13,14,13,14,13,13,14,14,14,16,17,17,17,17,17,18,19,20,20,20,20,21,21,22,22,22,24,24,25,26,26,26,27,27,28,28,28,28,28,29,30,31,
31,32,34,35,35,36,37,38,38,39,41,42,43,45,48,50,51,53,53,52,53,55,58,59,63,66,70,75,78,82,85,86,88,91,93,95,106,121,123,115,101,98,98,101,105,101,94,88,85,86,87,89,91,90,89,90,89,87,85,81,76,71,68,65,63,58,
55,53,49,47,46,45,44,44,44,44,43,40,36,33,31,31,30,29,28,27,26,25,26,27,26,25,24,24,23,22,22,22,23,23,24,23,22,21,18,18,18,18,16,16,15,15,14,14,14,13,12,11,10,10,11,12,12,12,12,12,11,11,11,11,10,10,10,10,10,
10,10,9,9,8,7,6,6,7,7,8,8,8,8,8,9,9,9,9,10,9,8,8,8,9,10,11,10,10,10,10,10,11,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
13,13,13,13,13,13,14,14,14,14,14,14,14,15,15,15,15,16,15,14,14,14,14,15,15,15,16,16,16,16,16,16,16,16,15,15,14,14,14,14,14,14,14,14,15,15,15,16,17,17,17,18,18,18,18,18,18,18,19,19,19,19,19,19,20,20,21,21,20,20,
20,20,20,20,20,20,20,20,20,20,20,20,21,21,21,21,22,22,23,23,23,24,24,24,24,24,24,24,24,24,25,26,26,27,28,29,30,31,31,33,35,34,34,38,38,35,37,36,36,35,33,33,33,33,32,31,31,30,29,29,29,29,28,28,28,28,28,28,28,27,
27,26,26,25,26,26,26,26,26,26,26,26,26,26,26,26,26,26,25,25,24,24,24,24,24,24,24,24,24,24,24,24,25,25,25,26,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,27,26,26,26,26,27,27,27,27,26,27,28,29,30,29,
29,30,30,30,30,30,30,30,30,30,31,31,31,31,31,31,31,31,31,31,31,32,32,32,32,32,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,33,33,33,33,33,33,33,33,33,33,33,33,
33,33,33,33,33,33,33,32,32,32,32,32,32,32,32,32,32,32,32,33,34,35,34,34,35,37,37,37,37,36,36,36,36,36,35,34,35,36,37,38,38,39,39,40,40,39,39,39,40,40,41,40,41,41,42,43,44,45,45,46,46,46,46,46,47,47,48,48,50,50,
51,51,52,53,53,53,54,54,54,55,55,56,57,57,57,58,59,60,62,63,64,64,66,67,68,68,67,68,69,70,73,74,74,74,73,73,75,76,74,72,73,77,81,84,83,82,82,81,80,79,79,78,77,76,76,75,76,76,74,74,74,74,73,73,73,74,74,74,74,74,
75,75,75,75,75,76,78,78,78,82,83,82,81,83,83,82,87,85,83,83,85,81,76,75,74,74,74,72,70,69,69,69,68,66,64,65,65,64,63,63,64,66,68,68,68,68,67,66,66,65,64,64,64,64,63,63,63,63,64,64,64,64,64,64,63,64,63,65,68,69,
74,84,96,121,144,150,142,127,104,85,76,71,69,68,68,67,67,66,63,65,67,66,65,63,65,65,67,66,67,66,66,66,66,65,63,62,61,61,60,60,61,61,61,61,61,61,60,60,60,60,59,59,60,60,59,59,59,59,58,58,58,58,59,59,59,59,58,58,
58,58,60,60,60,60,63,62,62,63,62,60,60,62,61,62,62,61,60,62,62,59,58,57,57,57,56,56,56,55,54,54,54,53,53,52,52,52,52,52,52,52,52,52,52,51,51,51,52,52,52,53,53,53,53,53,53,53,53,53,52,52,52,52,51,51,51,51,51,51,
50,50,48,48,48,48,49,49,49,49,49,49,49,48,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,47,46,46,47,46,46,46,45,45,45,45,46,46,46,46,46,46,47,47,47,48,48,48,48,48,48,48,48,48,48,49,
49,49,49,49,49,50,49,49,49,49,49,49,49,49,49,49,49,49,48,49,50,50, };
int B[] =
{
23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,25,25,25,26,26,27,27,25,26,26,26,26,26,26,26,27,27,27,28,27,28,27,27,28,28,28,30,30,30,31,31,31,32,33,34,34,34,34,35,34,35,35,35,35,35,36,37,38,38,39,39,
40,40,41,41,41,42,43,44,45,46,45,46,46,47,46,47,48,49,50,51,52,55,58,60,61,63,63,62,61,61,62,61,65,67,69,71,75,79,82,81,83,86,88,90,99,114,117,109,96,93,93,97,98,95,88,83,80,80,81,83,82,81,80,80,82,80,78,74,71,66,
63,61,60,57,54,52,48,46,45,44,45,45,46,47,48,45,41,38,35,35,37,36,35,34,35,34,34,35,36,35,34,34,32,33,34,34,37,37,38,37,36,35,35,35,34,34,33,33,32,32,31,31,31,30,29,28,27,27,28,29,29,29,29,29,28,28,28,28,27,27,27,
27,27,27,27,26,25,24,25,24,24,25,25,26,26,26,26,26,27,27,27,27,28,27,26,26,26,27,28,29,28,28,28,28,28,29,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,
30,30,30,30,30,30,30,30,30,30,30,30,30,30,31,31,31,31,31,31,31,32,32,32,32,33,32,31,33,33,33,34,34,34,35,35,35,35,35,35,35,35,34,34,34,34,34,34,34,34,34,34,35,35,35,36,37,37,39,40,40,40,40,40,40,40,41,41,41,41,41,
41,39,39,40,40,40,40,40,40,40,40,40,40,40,40,40,40,41,41,42,42,42,42,45,45,46,46,46,47,47,47,49,49,49,49,52,52,55,56,56,57,58,59,58,59,59,61,63,62,62,66,66,63,65,64,64,63,61,61,61,61,60,59,59,58,57,57,57,57,56,56,
56,56,56,56,56,55,55,54,54,53,53,53,53,53,53,53,53,53,53,53,53,53,51,51,50,50,49,49,49,49,49,49,49,49,49,49,49,51,52,52,52,53,54,54,54,54,54,54,54,54,54,54,54,56,56,56,56,56,56,56,56,56,57,57,57,57,58,58,58,58,56,
57,58,59,59,58,58,59,59,59,59,59,59,59,59,59,60,60,60,60,60,60,60,60,60,60,60,61,61,61,61,61,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,59,61,61,61,61,61,61,61,61,
61,61,61,61,61,61,61,61,63,63,63,62,62,62,62,62,62,62,62,62,62,62,62,62,63,63,63,63,64,66,66,66,66,65,65,65,65,65,65,64,65,66,67,68,69,70,70,71,71,70,70,70,71,71,71,70,73,73,74,75,76,77,78,79,79,79,80,80,81,81,82,
82,81,81,82,82,83,84,84,84,85,85,85,86,86,87,88,88,88,89,90,91,93,94,95,95,97,98,98,98,98,99,97,98,101,102,102,102,101,101,101,102,100,98,99,103,107,110,109,108,109,108,109,108,108,107,106,105,107,106,108,108,108,
108,108,108,107,105,107,108,108,108,111,111,111,111,111,111,109,110,112,112,113,117,118,117,119,121,118,117,122,120,118,118,117,113,108,107,106,106,106,104,102,101,101,101,100,98,99,100,101,100,99,99,100,102,104,
104,104,104,105,104,104,103,102,102,102,102,100,100,102,102,100,100,100,100,100,100,99,100,101,103,106,107,114,124,135,160,183,189,182,167,144,125,118,113,111,110,109,108,108,107,107,109,111,110,109,107,108,108,
110,109,109,108,108,108,108,107,105,104,103,103,102,102,103,103,103,103,103,103,102,102,102,102,101,101,101,101,100,100,100,100,99,99,99,99,99,99,99,99,99,99,99,99,100,100,100,100,105,104,104,105,107,105,105,107,
106,107,107,106,102,104,104,101,100,99,99,99,98,98,98,97,96,96,96,95,95,94,94,94,94,94,94,94,94,94,94,93,93,93,94,94,94,95,95,95,95,95,95,95,95,95,94,94,94,94,93,93,93,93,93,93,92,92,93,93,93,93,94,94,94,94,94,94,
94,93,92,92,92,92,92,92,92,92,92,92,92,92,92,92,93,93,93,93,93,93,93,93,93,93,93,93,92,92,93,92,91,91,90,90,90,90,91,91,91,91,92,92,92,92,92,93,93,93,93,93,93,93,93,93,93,94,94,94,94,94,94,95,97,97,97,97,99,99,99,
99,97,97,97,97,96,97,99,99,
};
// 主函数
int main()
{
	SetProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE);
	// 创建绘图窗口
	initgraph(1400, 1400, 1);
	int lk = 400, g = 0;
	g_pBuf11 = GetImageBuffer();
	

	BeginBatchDraw();		// 开启批量绘图
	ExMessage m;
	DWORD* g_pBuf = GetImageBuffer();
	IMAGE img(1400, 1400);
	SetWorkingImage(&img);
	for (int i = 0; i < getheight(); i++)
	{
		for (int k = 0; k < getwidth(); k++)
		{
			putpixel(k, i, RGB(R[i], G[i], B[i]));
		}
	}
	while (true)

	{	// 获取一条鼠标或按键消息
		SetWorkingImage();
		// 将 img 对象显示在绘图窗口中
		putimage(10, 10, &img);

		rec(100, 100, 200, 200, RGB(0, 0, 255));
		rec(150, 150, 150 + 100, 150 + 100, GREEN);
		rec(200, 200, 200 + 100, 200 + 100, BLUE);
		rec(200 + 50, 200 + 50, 250 + 100, 250 + 100, WHITE);
		rec(300, 300, 300 + 100, 300 + 100, LIGHTMAGENTA);
		rec(250 + 100, 250 + 100, 350 + 100, 350 + 100, YELLOW);

		star1(600, 500, lk);
		if (lk == 400)
		{
			g = -1;
		}
		if (lk == 1)
		{
			g = 1;
		}
		lk += g;
		FlushBatchDraw();
		cleardevice();
	}
	_getch();
	EndBatchDraw();
	closegraph();
	return 0;
}
ava
随波逐流

2023-6-1

0

抱歉,听不懂你的问题

ava
慢羊羊

2023-6-4

就是关于一个星形防止重复填充问题 -  随波逐流  2023-6-5
技术讨论社区