Community:Science/Robotics/Scripts/ImageGrabber
< Community:Science | Robotics | Scripts
2011年11月3日 (木) 04:51時点におけるwiki>Mindronesによる版 (moved Robotics/Scripts/ImageGrabber to Community:Science/Robotics/Scripts/ImageGrabber: moving under Community:Science ("Community" being a new namespace))
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'