opencv使用imageData读取像素值问题

#include <iostream>
#include <highgui.h>
#include <cv.h>
#include <cxcore.h>
using namespace std;

int main()
{
IplImage* img=cvLoadImage("C:\\Users\\Administrator\\Desktop\\项目\\opencv练习\\114___12\\7.png");
for(int y=0;y<img->height;y++)
{
int* p=(int*)(img->imageData+y*img->widthStep);
for(int x=0;x<img->width;x++)
{
cout<<(int)*(p+x)<<" ";
}

}
return 0;
}
1.段是代码,所读取的图片是一张QQ截图的纯白图片,理论上应该全部显示255,可是输出结果全部都是-1.
2.读取另一张普通照片,输出下图:

3.前段时间这段程序还可以正常输出的,现在用就出问题了。
初学者,谢谢指导!
IplImage* img=cvLoadImage(imageName);

cout<<img->width<<","<<img->height<缓州<","<<img->widthStep;
for(int y=0;y<img->height;y++)
{
unsigned char* p=(unsigned char*)(img->imageData+y*img->widthStep);
for(int x=0;x<img->width*img->nChannels;x++)
{
printf("%d ",p[x]);
}

}
你碰坦为什么要改为int型呢,存储的是char,你使用int型导致寻笑哪桐址方式改变,访问了越界的内存。另外,你确定你的图像是单通道图像么?
用CV_IMAGE_ELEM(src,uchar,y,x)