
visual c++ mfc 怎么实现封闭图形的填充
1个回答
展开全部
#7楼 得分:0回复于:2009-07-10 10:34:44CImage * gTranslation(CImage *pSrcImage, int tran_x, int tran_y)//平移
{
if(pSrcImage == NULL || pSrcImage->IsNull()) return NULL;
CImage *pDestImage = new CImage;
int width = gRound(pSrcImage->GetWidth());
int height = gRound(pSrcImage->GetHeight());
int destWidth = gRound(width+tran_x);
int destHeight = gRound(height+tran_y);
if(!pDestImage->Create(destWidth, destHeight, 24))
{
delete pDestImage;
return NULL;
}
for(int i=0;i<width+tran_x;i++)
{
for(int j= 0;j<height+tran_y;j++)
{
BYTE *pd = (BYTE *)pDestImage->GetPixelAddress(i, j);
*pd = 255;
*(pd+1) = 255;
*(pd+2) = 255;
}
}
for(int i=0;i<width;i++)
{
for(int j= 0;j<height;j++)
{ BYTE *ps = (BYTE *)pSrcImage->GetPixelAddress(i, j);
BYTE *pd = (BYTE *)pDestImage->GetPixelAddress(i+tran_x, j+tran_y);
*pd = *ps;
*(pd+1) = *(ps+1);
*(pd+2) = *(ps+2);
}
}
return pDestImage;
}
CImage * gScaleImage(CImage *pSrcImage, float sx, float sy)//缩放
{
if(pSrcImage == NULL || pSrcImage->IsNull()) return NULL;
CImage *pDestImage = new CImage;
int width = gRound(pSrcImage->GetWidth());
int height = gRound(pSrcImage->GetHeight());
int destWidth = gRound(width*sx);
int destHeight = gRound(height*sy);
if(!pDestImage->Create(destWidth, destHeight, 24))
{
delete pDestImage;
return NULL;
}
for(int j=0; j<destHeight; j++)
{
float y = j/sy;
int n = int(y);
float q = y - n;
//获得原始图象的第n行的首地址像素值
BYTE *ps0 = (BYTE *)pSrcImage->GetPixelAddress(0, n);
BYTE *ps1 = n == height-1 ? ps0 : (BYTE *)pSrcImage->GetPixelAddress(0, n+1);
BYTE *pd = (BYTE *)pDestImage->GetPixelAddress(0, j);
for(int i=0; i<destWidth; i++)
{
float x = i/sx;
int m = int(x);
float p = x-m;
BYTE *ps00 = ps0+m*3; //获得原始图象的第n行m列的像素值
BYTE *ps01 = ps1+m*3;
BYTE *ps10 = m == width-1 ? ps00 : ps00+3;
BYTE *ps11 = m == width-1 ? ps01 : ps01+3;
for(int k=0; k<3; k++)
{
float d00 = *ps00;
float d10 = *ps10;
float d01 = *ps01;
float d11 = *ps11;
//双线性插值求像素值
int d = gRound( gBiLinear(d00, d10, d01, d11, p, q) );
if(d < 0) d = 0;
if(d > 255) d = 255;
*pd = d;
ps00++; ps10++;
ps01++; ps11++;
pd++;
}
}
}
return pDestImage;
}
{
if(pSrcImage == NULL || pSrcImage->IsNull()) return NULL;
CImage *pDestImage = new CImage;
int width = gRound(pSrcImage->GetWidth());
int height = gRound(pSrcImage->GetHeight());
int destWidth = gRound(width+tran_x);
int destHeight = gRound(height+tran_y);
if(!pDestImage->Create(destWidth, destHeight, 24))
{
delete pDestImage;
return NULL;
}
for(int i=0;i<width+tran_x;i++)
{
for(int j= 0;j<height+tran_y;j++)
{
BYTE *pd = (BYTE *)pDestImage->GetPixelAddress(i, j);
*pd = 255;
*(pd+1) = 255;
*(pd+2) = 255;
}
}
for(int i=0;i<width;i++)
{
for(int j= 0;j<height;j++)
{ BYTE *ps = (BYTE *)pSrcImage->GetPixelAddress(i, j);
BYTE *pd = (BYTE *)pDestImage->GetPixelAddress(i+tran_x, j+tran_y);
*pd = *ps;
*(pd+1) = *(ps+1);
*(pd+2) = *(ps+2);
}
}
return pDestImage;
}
CImage * gScaleImage(CImage *pSrcImage, float sx, float sy)//缩放
{
if(pSrcImage == NULL || pSrcImage->IsNull()) return NULL;
CImage *pDestImage = new CImage;
int width = gRound(pSrcImage->GetWidth());
int height = gRound(pSrcImage->GetHeight());
int destWidth = gRound(width*sx);
int destHeight = gRound(height*sy);
if(!pDestImage->Create(destWidth, destHeight, 24))
{
delete pDestImage;
return NULL;
}
for(int j=0; j<destHeight; j++)
{
float y = j/sy;
int n = int(y);
float q = y - n;
//获得原始图象的第n行的首地址像素值
BYTE *ps0 = (BYTE *)pSrcImage->GetPixelAddress(0, n);
BYTE *ps1 = n == height-1 ? ps0 : (BYTE *)pSrcImage->GetPixelAddress(0, n+1);
BYTE *pd = (BYTE *)pDestImage->GetPixelAddress(0, j);
for(int i=0; i<destWidth; i++)
{
float x = i/sx;
int m = int(x);
float p = x-m;
BYTE *ps00 = ps0+m*3; //获得原始图象的第n行m列的像素值
BYTE *ps01 = ps1+m*3;
BYTE *ps10 = m == width-1 ? ps00 : ps00+3;
BYTE *ps11 = m == width-1 ? ps01 : ps01+3;
for(int k=0; k<3; k++)
{
float d00 = *ps00;
float d10 = *ps10;
float d01 = *ps01;
float d11 = *ps11;
//双线性插值求像素值
int d = gRound( gBiLinear(d00, d10, d01, d11, p, q) );
if(d < 0) d = 0;
if(d > 255) d = 255;
*pd = d;
ps00++; ps10++;
ps01++; ps11++;
pd++;
}
}
}
return pDestImage;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询