首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

图像转置 memset解决方案

2012-03-29 
图像转置 memset第一次调用转置函数是没问题,为什么第二次走到memset这条语句时就出问题了?void GeometryT

图像转置 memset
第一次调用转置函数是没问题,为什么第二次走到memset这条语句时就出问题了?
void GeometryTrans::ZhuanZhi()
{
// 释放旧的图像数据
if (m_pImgDataOut != NULL )
{
delete [] m_pImgDataOut;
m_pImgDataOut = NULL;

// 输出图像的宽和高
m_imgHeightOut = m_imgWidth;
m_imgWidthOut = m_imgHeight;

// 输入图像的行字节数
int lineByteIn = (m_imgWidth * m_nBitCount/8 + 3) / 4 * 4;

// 输出图像的行字节数
int lineByteOut = (m_imgWidthOut * m_nBitCountOut/8 + 3) / 4 * 4;

// 每像素占字节数
int nBytePixel = m_nBitCountOut / 8;


// 为输出图像开辟空间
m_pImgDataOut = new unsigned char [lineByteOut * m_imgHeightOut];
memset(m_pImgDataOut, 0, m_imgWidthOut * lineByteOut);
for (int i = 0; i < m_imgHeightOut; i++)
{
for (int j = 0; j < m_imgWidthOut; j++)
{
for (int k = 0; k < nBytePixel; k++)
{
*(m_pImgDataOut + i * lineByteOut + j * nBytePixel + k)
= *(m_pImgData + j * lineByteIn + i * nBytePixel + k);
}

}
}

}

[解决办法]
你写错了。。。

imgWidthOut 应该是 m_imgHeightOut 吧
[解决办法]
可能m_pImgDataOut 越界了。
[解决办法]
越界了,原因是imgHeightOut写成了m_imgWidthOut
void GeometryTrans::ZhuanZhi()
{
// 释放旧的图像数据
if (m_pImgDataOut != NULL )
{
delete [] m_pImgDataOut;
m_pImgDataOut = NULL;
}
// 输出图像的宽和高
m_imgHeightOut = m_imgWidth;
m_imgWidthOut = m_imgHeight;

// 输入图像的行字节数
int lineByteIn = (m_imgWidth * m_nBitCount/8 + 3) / 4 * 4;

// 输出图像的行字节数
int lineByteOut = (m_imgWidthOut * m_nBitCountOut/8 + 3) / 4 * 4;

// 每像素占字节数
int nBytePixel = m_nBitCountOut / 8;


// 为输出图像开辟空间
m_pImgDataOut = new unsigned char [lineByteOut * m_imgHeightOut];
memset(m_pImgDataOut, 0, m_imgHeightOut * lineByteOut);
 
 

热点排行