回复: 使用Qt的QLabel获取绘图句柄问题!
#11 回 nuanbing222 的帖子 [dbzhang800 09-24 11:51]
nuanbing222:
我的图片格式是RGB888的,内存的长度是768*576*3
如果你说的属实,这对QImage应该很简单,直接用构造函数就行了。
但是你提到了QImage::fromData() 和 崩溃什么的,只能说明:你在不分青红皂白地乱试
#12 回 dbzhang800 的帖子 [nuanbing222 09-24 12:07]
dbzhang800:如果你说的属实,这对QImage应该很简单,直接用构造函数就行了。
但是你提到了QImage::fromData() 和 崩溃什么的,只能说明:你在不分青红皂白地乱试
....... (2014-09-24 11:51)
那能不能提示一下使用哪个构造函数。。。
#13 [dbzhang800 09-24 12:27]
多个都可以,包括你试过的那个
#14 回 nuanbing222 的帖子 [xuang 09-24 13:03]
nuanbing222:那能不能提示一下使用哪个构造函数。。。
(2014-09-24 12:07)
如果你不是一定要对采集卡的原始内存数据进行操作,我建议你先new一个QImage,然后用QImage的bits()获取这个QImage的图像数据指针,然后用for循环或者memcpy将原始的图像数据拷贝过来。
#15 [roywillow 09-24 14:35]
我觉得你能明确那个format没错就成功了一半了吧,对应的QImage的format应该是QImage::Format_RGB888,你可以构造的时候就传入data,或者构造完再修改也可以
另外如果你传入char*作为data的话,要确保这个char*保持有效才可以,Qt是不会自己进行拷贝的,文档说的很清楚:
QImage::QImage(uchar * data, int width, int height, Format format, QImageCleanupFunction cleanupFunction = 0, void * cleanupInfo = 0)
Constructs an image with the given width, height and format, that uses an existing memory buffer, data. The width and height must be specified in pixels, data must be 32-bit aligned, and each scanline of data in the image must also be 32-bit aligned.
The buffer must remain valid throughout the life of the QImage and all copies that have not been modified or otherwise detached from the original buffer. The image does not delete the buffer at destruction. You can provide a function pointer cleanupFunction along with an extra pointer cleanupInfo that will be called when the last copy is destroyed.
If format is an indexed color format, the image color table is initially empty and must be sufficiently expanded with setColorCount() or setColorTable() before the image is used.
似乎从文档看传入的data必须是32位对齐的?即使是RGB888的24位数据?可能下面那个带bytesPerLine的更有用?