zoukankan      html  css  js  c++  java
  • 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'
    

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

    求大神指导更好的方法!

  • 相关阅读:
    Problem 3
    Problem 2
    Problem 1
    Python基础 装饰器
    算法——狄克斯特拉算法
    A Knight's Journey POJ 2488
    多校10 1007 CRB and Queries
    多校9 1007 Travelling Salesman Problem
    多校8 1008 Clock
    多校7 1005 The shortest problem
  • 原文地址:https://www.cnblogs.com/ahfuzhang/p/9975168.html
Copyright © 2011-2022 走看看