ImageViewport: image

image
  • Returns the image data.

Return Type: 

  • integer list [r,g,b,a] for every pixel in the image.

a:
  • alpha color channel
  • Type:  integer
  • Range: 0 to 255
b:
  • blue color channel
  • Type:  integer
  • Range: 0 to 255
g:
  • green color channel
  • Type:  integer
  • Range: 0 to 255
r:
  • red color channel
  • Type:  integer
  • Range: 0 to 255
Sample Code

###################### get the image data

# import bge module
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get list of objects in scene
objList = scene.objects

# get object to render to
# my object is named Security_Monitor
obj = objList["Security_Monitor"]

# get the Security_Monitor material ID
# Name of my render material is Screen
matID = bge.texture.materialID(obj, "MAScreen")

# get the texture
viewport_texture = bge.texture.Texture(obj, matID)

# get the texture image source
viewport_texture.source = bge.texture.ImageViewport()

# get the image data
data = viewport_texture.source.image

# save as an object property
obj["image_viewport"] = viewport_texture

# update texture
viewport_texture.refresh(True)