Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尽快将ctypes数据转换为python字符串_Python_Pyqt4_Ctypes - Fatal编程技术网

尽快将ctypes数据转换为python字符串

尽快将ctypes数据转换为python字符串,python,pyqt4,ctypes,Python,Pyqt4,Ctypes,我正在尝试用PyQt4编写一个视频应用程序,并使用Python ctypes连接到一个旧的遗留视频解码器库中。该库提供32位ARGB数据,我需要将其转换为QImage。我的工作原理如下: # Copy the rgb image data from the pointer into the buffer memmove(self.rgb_buffer, self.rgb_buffer_ptr, self.buffer_size) # Copy the buffer to a python s

我正在尝试用PyQt4编写一个视频应用程序,并使用Python ctypes连接到一个旧的遗留视频解码器库中。该库提供32位ARGB数据,我需要将其转换为QImage。我的工作原理如下:


# Copy the rgb image data from the pointer into the buffer
memmove(self.rgb_buffer, self.rgb_buffer_ptr, self.buffer_size)

# Copy the buffer to a python string
imgdata = ""
for a in self.rgb_buffer:
    imgdata = imgdata + a

# Create a QImage from the string data
img = QImage(imgdata, 720, 288, QImage.Format_ARGB32)
问题是,ctypes将数据输出为类型“
ctypes.c\u char\u Array\u 829440
”,我需要将其转换为python字符串,以便构建QImage。我的复制机制目前每幅图像需要300毫秒,所以速度非常慢。解码和显示部分的过程只需要大约50毫秒


有谁能想到我可以采取什么巧妙的捷径来加速这个过程,避免像我现在这样复制两次缓冲区?

ctypes.c\u char\u Array\u 829400实例具有属性
.raw
,它返回一个可能包含NUL字节的字符串,以及属性
.value
,如果字符串包含一个或多个字节,则返回第一个NUL字节的字符串

但是,您也可以使用ctypes访问
self.rgb\u buffer\u ptr
处的字符串,如下所示:
ctypes.string_at(self.rgb_buffer_ptr,self.buffer_size)
;这将避免对memmove调用的需要。

非常感谢,string_at函数起到了作用。我真的需要更好地阅读文档。我检查了几次,还是没看到那一个!