c python函数图像_python: c_char_p指向的bitmap图像数据,通过c_char_Array最终赋值给PIL的Image对象...

def GetCurrentImage(self):

ok, bitmap, buff_len = self.GetCurrentFrameBitmap() #调用C函数,返回位图数据的指针. bitmap是c_char_p类型

if not ok:

return False,None,'GetCurrentFrameBitmap fail:code=%d, msg=%s'% \

(reader.LastErrorCode(), reader.LastErrorMessage())

ret,width,height = self.GetVideoRect()

if not ret:

return False,None,'GetVideoRect fail:code=%d, msg=%s'%(reader.LastErrorCode(), reader.LastErrorMessage())

BitmapType = c_char*buff_len #创建一个数组对象

arr = BitmapType() #数组的实例

memmove(arr, bitmap, buff_len) #拷贝内容

#img = Image.frombytes('RGB', (width, height), arr)

img = Image.frombuffer('RGB', (width, height), arr, 'raw', 'RGB', 0, 1) #数组直接映射为图片对象

return True,img,'success'

这个方法试了三小时才试出来。

求大神指导更好的方法!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值