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'
這個方法試了三小時才試出來。
求大神指導更好的方法!