QImage的用法
QImage提供了幾種加載圖像文件的方法:
(1)構(gòu)造QImage對象
Image myImage1 = QImage(filename); 根據(jù)文件名打開圖像
支持的圖片格式是:
(2)QImage(uchar *data, int width, int height, Format format …)
用數(shù)據(jù)構(gòu)建一個圖像,例如:
QImage nImage((uchar *)mAVFrameRGB->data[0],mTargetWidth,
mTargetHeight,QImage::Format_RGB888);
支持RGB的數(shù)據(jù)格式
(3)QImage QImage::fromData(const uchar *data, int size, const char *format = Q_NULLPTR) //有格式要求PNG or JPG
好了,現(xiàn)在我們需要對圖像數(shù)據(jù)操作,32位圖像無疑是最簡單的,因為它數(shù)據(jù)是對齊的。用width表示圖像寬度,height表示圖像高度。
首先熟悉幾個函數(shù):
a、uchar* bits(); 可以獲取圖像的首地址
b、int byteCount(); 圖像的總字節(jié)數(shù)
c、int bytesPerLine(); 圖像每行字節(jié)數(shù)
1、QImage::Format_RGB32,存入格式為B,G,R,A 對應(yīng) 0,1,2,3
QImage::Format_RGB888,存入格式為R, G, B 對應(yīng) 0,1,2QImage::Format_Indexed8,需要設(shè)定顏色表,QVector<QRgb>總結(jié)
- 上一篇: php另类上传图片的方法(PHP用Soc
- 下一篇: python 中main函数总结