很多人都为如何将内存中某一个格式的数据如何转换成为图片数据显示到屏幕上犯愁,因为这是实现处理视频的一个关键部分,我曾经也是,所以深知其不容易,如今,我这里问题已经解决,所以将解决方法备份与此,仅供参考。
这里提供处理两种数据格式的方法,一种是处理RGB24格式,另一种是RGBA32格式;
说明:
内存中数据保存在pv_frame指针指向的内存空间中;
图象宽度为v_width, the height of it is v_height;(高度是v_height);下面展示方法调用;
RGB24:
/**
* lsosa.BIT
*/
int i;
int r, g, b;
QRgb *point;
uchar *bit;
QImage *pVideoImage = new QImage(width, height, 32);
setWFlags(getWFlags() | Qt::WRepaintNoErase);
// these codes should be optimized in future;
// high cpu taked here;
i = 0;
bit = (uchar *)(_frame);
for(int y = 0; y < v_height; y ++){
for ( int x = 0; x < v_width; x ++ ){
r = (int)bit
;
g = (int)bit[i+1];
b = (int)bit[i+2];
point = (QRgb *)pVideoImage->scanLine(y) + x;
*point = qRgb(r, g, b);
i += 3;
}
}
bitBlt(this, 0, 0, pVideoImage);
the details is here:
http://www.qtcn.org/bbs/read.php?tid=3648&page=e&fpage=5
http://www.qtcn.org/bbs/read.php?tid=4990&page=e&fpage=1
RGBA32:
/**
* lsosa.BIT
*/
QImage *pv_images;
if ( pv_images == NULL ){
QImage pv_images = new QImage((uchar *)pv_frame, \
v_width, v_height, 32, NULL, 0, QImage::LittleEndian);
if ( pv_images == NULL ){
return -1;
}
}
all is this...