我尝试用GetImageBuffer(NULL)获取绘图窗口的一个像素的DWORD值d,用BGR(d)作为setfillcolor的参数,但是绘制出来的填充颜色与那个像素点的颜色不一样,是为什么呢?应该怎么修改呢?
源代码如下:
#include<easyx.h>
const int _wid = 1280, _hei = 800;
int nPaletteX = _wid - 285, nPaletteY = 32, nPaletteWidth = 256, nPaletteHeight = 256;/*调色板的坐标以及宽高*/
bool fnIsAviField(int x, int y, int nXMin , int nXMax , int nYMin , int nYMax )
{
return (x > nXMin&&x<nXMax&&y>nYMin&&y < nYMax);
}
void fnFlush(DWORD dValue,int nLength)
{
int i;
DWORD *dp = GetImageBuffer(NULL);
for (i = 0; i < _wid*_hei; i++)
{
dp[i] = dValue;
if (!(i%nLength))
dValue++;
}
}
bool fnDrawPalette(int x, int y, int nWidth, int nHeight, bool bIsUsed = false, DWORD dValue = RGB(256, 256, 256))
{
DWORD *dp = GetImageBuffer(NULL), dColor = 0;
int i, j;
if (x<0 || y<0 || x>_wid || y>_hei)
return false;
dp += x + y * _wid;
for (i = 0; i < nHeight; i++)
{
if (y + i >= _hei)
break;
for (j = 0; j < nWidth; j++)
{
if (j + x >= _wid)
break;
if (!bIsUsed)
dp[j] = RGB(i, j, 256);
else
dp[j] = RGB(GetRValue(dValue), GetGValue(dValue), j);
}
dp += _wid;
}
return true;
}
int main(void)
{
DWORD nGloColor;
int i;
ExMessage *stMsg=new ExMessage;
initgraph(_wid,_hei);
fnFlush(RGB(231, 177, 134), _wid*_hei/(16) );
fnDrawPalette(nPaletteX, nPaletteY, nPaletteWidth, nPaletteHeight);
while (1)
{
if (peekmessage(stMsg))
{
if (stMsg->message==WM_LBUTTONDOWN)
{
if (fnIsAviField(stMsg->x, stMsg->y, nPaletteX, nPaletteX + nPaletteWidth, nPaletteY, nPaletteY + nPaletteHeight))
{
nGloColor = GetImageBuffer(NULL)[stMsg->x + (stMsg->y - 1)*_wid];
for (i = 0; i < 32; i++)
fnDrawPalette(nPaletteX, 1.08*nPaletteHeight + nPaletteY + i, nPaletteWidth, 1, true, nGloColor);
}
else if (fnIsAviField(stMsg->x, stMsg->y, nPaletteX, 1.08*nPaletteHeight + nPaletteY, nPaletteWidth, 32))
{
nGloColor = GetImageBuffer(NULL)[stMsg->x + (stMsg->y - 1)*_wid];
Sleep(1024);
}
else
{
//setfillcolor(BGR(GetImageBuffer(NULL)[stMsg->y*_wid + stMsg->x]));
setfillcolor(BGR(nGloColor));
fillcircle(stMsg->x, stMsg->y, 32);
}
}
flushmessage();
}
}
delete stMsg;
closegraph();
return 0;
}