2013-05-31 26 views
1

当我尝试使用Cimg库读取jpg文件时,出现堆栈溢出错误,而其他格式的bmp正在工作文件。使用Cimg库读取jpeg图像时发生堆栈溢出错误

我该如何解决它?

#include"CImg.h" 
    #include<stdio.h> 
    using namespace cimg_library; 
    int main() 
    { 
      CImg<unsigned char> src("d:\\sidimg.jpg"); 
      int width = src.width(); 
      int height = src.height(); 
      unsigned char* ptr = src.data(0,0); 
      int count=0; 
       while(count!= width*height) 
       { 

        printf("%d",*ptr); 
        ptr++; 
        count++; 
       } 
    } 
+0

看起来应该是,而计数<宽度*高度,因为图像不是0索引我不认为(从像素1开始) – Magn3s1um

+0

while循环没有问题,我测试这个程序与bmp文件工作正常。问题与JPG图像 – siddstuff

+0

当你重写你的缓冲区(或堆栈)时发生堆栈溢出。也许你应该尝试刷新标准输出,因为可能printf正在建立并导致溢出。除此之外,它看起来很好,并且不会是一个问题,因为stdout应该在其满时自动刷新自身。 – Magn3s1um

回答

0

对不起,我回答晚了,但你必须有convert.exeImageMagick包在同一个目录,其中程序以读取/写入JPEG图像执行。