首页 > 编程语言 > 详细

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

时间:2018-11-17 20:16:58      阅读:347      评论:0      收藏:0      [点我收藏+]
    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‘

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

求大神指导更好的方法!

 

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

原文:https://www.cnblogs.com/ahfuzhang/p/9975168.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!