19,468
社区成员
发帖
与我相关
我的任务
分享
bool CTGView::ImageCopy(int32_t newx, int32_t newy, const CImage &srcImage, CImage &destImage)
{
int i,j;//循环变量
if(srcImage.IsNull())
return FALSE;
//源图像参数
BYTE* srcPtr=(BYTE*)srcImage.GetBits();
int srcBitsCount=srcImage.GetBPP();
int srcWidth=srcImage.GetWidth();
int srcHeight=srcImage.GetHeight();
int srcPitch=srcImage.GetPitch();
//销毁原有图像
if( !destImage.IsNull())
{
destImage.Destroy();
}
//创建新图像
if(srcBitsCount==32) //支持alpha通道
{
destImage.Create(newx,newy,srcBitsCount,1);
}
else
{
destImage.Create(newx,newy,srcBitsCount,0);
}
//加载调色板
if(srcBitsCount<=8&&srcImage.IsIndexed())//需要调色板
{
RGBQUAD pal[256];
int nColors=srcImage.GetMaxColorTableEntries();
if(nColors>0)
{
srcImage.GetColorTable(0,nColors,pal);
destImage.SetColorTable(0,nColors,pal);//复制调色板程序
}
}
//目标图像参数
BYTE *destPtr=(BYTE*)destImage.GetBits();
int destPitch=destImage.GetPitch();
//复制图像数据
for(i=0 ; i<newy;i++)
{
memcpy( destPtr+i*destPitch, srcPtr+i*srcPitch, abs(srcPitch) );
}
return TRUE;
}