【发布时间】:2012-08-24 14:37:53
【问题描述】:
这是我的功能,上面写着
变量 cinfo 周围的堆栈已损坏。
它说问题出在第 551 行,这是发布的代码的最后一行。
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE* pOutFile; //Target file
int nSampsPerRow; //Physical row width in image buffer
JSAMPARRAY jsmpArray; //Pixel RGB buffer for JPEG file
cinfo.err = jpeg_std_error(&jerr); //Use default error handling (ugly!)
jpeg_create_compress(&cinfo);
if ((pOutFile = fopen(csJpeg, "wb")) == NULL)
{
*pcsMsg = "Cannot open ";
*pcsMsg += csJpeg;
jpeg_destroy_compress(&cinfo);
return FALSE;
}
jpeg_stdio_dest(&cinfo, pOutFile);
LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)hDib;
cinfo.image_width = lpbi->biWidth; //Image width and height, in pixels
cinfo.image_height = lpbi->biHeight;
cinfo.input_components = 3; //Color components per pixel
//(RGB_PIXELSIZE - see jmorecfg.h)
cinfo.in_color_space = JCS_RGB; //Colorspace of input image
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo,
nQuality, //Quality: 0-100 scale
TRUE); //Limit to baseline-JPEG values
jpeg_start_compress(&cinfo, TRUE);
//JSAMPLEs per row in output buffer
nSampsPerRow = cinfo.image_width * cinfo.input_components;
//Allocate array of pixel RGB values
jsmpArray = (*cinfo.mem->alloc_sarray)
((j_common_ptr) &cinfo,
JPOOL_IMAGE,
nSampsPerRow,
cinfo.image_height);
if (DibToSamps(hDib,
nSampsPerRow,
cinfo,
jsmpArray,
pcsMsg))
{
//Write the array of scan lines to the JPEG file
(void)jpeg_write_scanlines(&cinfo,
jsmpArray,
cinfo.image_height);
}
jpeg_finish_compress(&cinfo); //Always finish
fclose(pOutFile);
jpeg_destroy_compress(&cinfo); //Free resources
if (*pcsMsg != "")
return FALSE;
else
return TRUE;
}
堆栈跟踪:> WindowBitmap.exe!CBitmapFile::JpegFromDib(void * hDib, int nQuality, ATL::CStringT > > csJpeg, ATL::CStringT > > * pcsMsg) 第 551 行 + 0x28 字节 C++
错误消息:运行时检查失败 #2 - 变量“cinfo”周围的堆栈已损坏。 pcsMsg 定义: CString* pcsMsg
【问题讨论】:
-
你能发布堆栈跟踪和错误消息吗?
-
a) 是什么“它”告诉您您的堆栈已损坏。 b) 你的参数是什么? pcsMsg 的使用看起来很奇怪
-
能否提供
pcsMsg的定义,以及函数原型。你使用设置 pcsMsg 看起来不对 -
嗨,很抱歉影响了您对 SO 的第一印象,但这是您之前问题的重复,这是不被宽恕的。相反,结束一个问题(就像你之前的问题一样)应该鼓励你改进它。您可以编辑之前的问题,并确保突出显示实际问题所在。注意:如果代码预览显示滚动条,则表明您可能必须自己进一步解决问题。
-
当一个问题被关闭时,你不应该再次重新发布它(甚至修改)。相反,请编辑您之前的问题并要求重新打开它。发布一条新消息意味着现在有重复消息,人们必须花时间清理它们并删除其他消息。 FAQ 详细介绍了 StackOverflow 的工作原理。谢谢。
标签: c++