Community:Science/Robotics/Scripts/ImageGrabber
< Community:Science | Robotics | Scripts
Image Grabber
The script grabs a very small portion of screen (8px X 8px) around the current position of the mouse, through the OpenGL buffer, and save it.
import Blender
from Blender.BGL import *
import Image
coords = Blender.Window.GetMouseCoords()
imX = 8
imY = 8
depth = 3 # 3 channels RGB
buf = Buffer(GL_BYTE, imX * imY * depth)
glReadPixels(coords[0], coords[1], imX, imY, GL_RGB, GL_BYTE, buf)
image = Image.new('RGB', (imX, imY))
for i in range(imX):
for j in range(imY):
pos = (i * imY + j) * depth
image.putpixel((i, j), ( buf.list[pos], buf.list[pos + 1], buf.list[pos + 2]))
image = image.transpose(2) #rotate 90 degre
image.save('test.png')
print 'Image saved'