|
本帖最后由 scg2635an 于 2011-12-3 10:36 编辑
在网上找的程序,修改后图像显示严重失真,有谁能帮忙看下吗?很急的
屏是240*320的,代码如下:
void Widget::do_view()
{
int ret ;
pp = (unsigned char*)malloc(320*240*2*sizeof(char));
frame = new QImage(pp,320,240,QImage::Format_RGB16);
video_fd = open(VIDEO_DEV_NODE,O_RDWR);
if(video_fd<0)
QMessageBox::warning(this,tr("VIDEO_DEV_NODE"),tr("VIDEO_DEV_NODE OPEN ERROR"));
ret = read(video_fd,pp,320*240*2);
if(ret<0)
QMessageBox::warning(this,tr("VIDEO_READ"),tr("VIDEO_READ ERROR"));
if(ioctl(cam_fd,VIDIOCGCAP, &(vd->capability))==-1); //后加的 读video_capability 中信息
QMessageBox::warning(this,tr("CAM_READ"),tr("CAM_READ ERROR"));
//QPainter *painter =new QPainter(this);
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(readFrame()));
timer->start(30);
}
void Widget::readFrame()
{
if(video_fd>0)
{
// update();
read(video_fd,pp,320*240*2);
frame = new QImage(pp,320,240,QImage::Format_RGB16);
frame->loadFromData((unsigned char*)pp,320*240*2*sizeof(char));
ui->label->setPixmap(QPixmap::fromImage(*frame,Qt::AutoColor));
free(pp);
pp = (unsigned char*)malloc(320*240*2*sizeof(char));
}
} |
|