unsigned char * Colore=new unsigned char[nWidth*nHeight*3];
for(y=0; y<nHeight ; y++ )
for(x=0 ; x<nWidth ; x++ )
{
Colore[x,y,0]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x );
Colore[x,y,1]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1 );
Colore[x,y,2]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2 );
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x)=((unsigned char)255-Colore[x,y,0]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1)=((unsigned char)255-Colore[x,y,1]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2)=((unsigned char)255-Colore[x,y,2]);
};
delete []Colore;
这一段程序运行正常,但下面的为什么不对呢?
unsigned char * Colore=new unsigned char[nWidth*nHeight*3];
for(y=0; y<nHeight ; y++ )
for(x=0 ; x<nWidth ; x++ )
{
Colore[x,y,0]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x );
Colore[x,y,1]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1 );
Colore[x,y,2]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2 );
}
for(y=0; y<nHeight ; y++ )
for(x=0 ; x<nWidth ; x++ )
{
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x)=((unsigned char)255-Colore[x,y,0]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1)=((unsigned char)255-Colore[x,y,1]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2)=((unsigned char)255-Colore[x,y,2]);
};
delete []Colore;
for(y=0; y<nHeight ; y++ )
for(x=0 ; x<nWidth ; x++ )
{
Colore[x,y,0]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x );
Colore[x,y,1]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1 );
Colore[x,y,2]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2 );
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x)=((unsigned char)255-Colore[x,y,0]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1)=((unsigned char)255-Colore[x,y,1]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2)=((unsigned char)255-Colore[x,y,2]);
};
delete []Colore;
这一段程序运行正常,但下面的为什么不对呢?
unsigned char * Colore=new unsigned char[nWidth*nHeight*3];
for(y=0; y<nHeight ; y++ )
for(x=0 ; x<nWidth ; x++ )
{
Colore[x,y,0]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x );
Colore[x,y,1]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1 );
Colore[x,y,2]=*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2 );
}
for(y=0; y<nHeight ; y++ )
for(x=0 ; x<nWidth ; x++ )
{
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x)=((unsigned char)255-Colore[x,y,0]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+1)=((unsigned char)255-Colore[x,y,1]);
*(pImageData+(nHeight-y-1)*nSaveWidth+3*x+2)=((unsigned char)255-Colore[x,y,2]);
};
delete []Colore;
LPBYTE类型。
我没有理解你的意思。Colore[x,y,0]表示的是点(x,y)的RED值。
从程序的运行结果来分析,似乎是我定义的Colore三维数组在第一次FOR循环中的值只得到一个,
所以在第二个循环中数组的值唯一导致运行结果不一样。但我不知道是为什么。
pImageData+(nHeight-y-1)*nSaveWidth+3*x+1 2
pImageData+(nHeight-y-1)*nSaveWidth+3*x+2 3
这三个算式对于不同的x,y取值是否会有重复的结果
比如 nHeight = 5, nSaveWidth = 1;
则对1有 x=y=0时, 1 的值是 4
对2有 x=0,y=1时 2 的值也是是 4
这样就把同一个地址的值给覆盖了,
如果是三维的,则用 Colore[x][y][n],
如果按一维处理,则需要根据你约定的排列方式算出一个index,再用Colore[index]。
请教一下,如果是动态数组,该如何定义和操作,我按你说的试了一下,编译通不过,
能否说详细一点,谢谢!