CxImage::CreateFromMatrix()

http://www.access911.net/getnews/doc1.asp?mode=a&bid=005010&aid=5395698

CDC *pDC = GetDC();
//高和宽
int x = _BackGroundRect->GetWidth();
int y = _BackGroundRect->GetHeight();
//存储象素内容
BYTE **pixelMatrix = new BYTE* [y];

for(int i = 0; i< y; i++)
pixelMatrix[i] = new BYTE[x*3];


for(int i = 1; i<= y; i++)
for( int j = 1; j<= x; j++)
{
COLORREF color = pDC->GetPixel(i,j);
pixelMatrix[i-1][j-1] = (BYTE)GetBValue(color);
pixelMatrix[i-1][j] = (BYTE)GetGValue(color);
pixelMatrix[i-1][j+1] = (BYTE)GetRValue(color);
}

CxImage image;
//从象素矩阵创建图像
image.CreateFromMatrix(pixelMatrix,x,y,24,3*x,1);
image.Save(_T("c:\\1.png"),2);

for(int i = 0; i<y; i++)
delete [] pixelMatrix[i];
delete [] pixelMatrix;

ReleaseDC(pDC);


你可能感兴趣的:(CxImage::CreateFromMatrix())