0

これは私の機能であり、それは言う

変数 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 - 変数 'c​​info' の周りのスタックが壊れています。pcsMsg 定義: CString* pcsMsg

4

1 に答える 1

0
jpeg_destroy_compress(&cinfo);

自動変数のメモリを解放します。これはcinfo、スコープ外になると 2 回目に解放されます。

関数 jpeg_destroy_compress() は、圧縮オブジェクトに関連付けられたすべてのメモリの割り当てを解除して解放します。

于 2012-08-24T14:41:14.453 に答える