Last active
August 17, 2018 01:36
-
-
Save hmasato/b72a95fbadf1c63b56ec to your computer and use it in GitHub Desktop.
[Maya, python, PyQt, PySide] grabFrameBufferToQImage (MImage and QPixmap) #screenshot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #hmasato | |
| #https://gist.github.com/hmasato/b72a95fbadf1c63b56ec | |
| #------------------------------ | |
| #grab frame buffer to QImage | |
| #------------------------------ | |
| import ctypes | |
| import maya.OpenMaya as om | |
| import maya.OpenMayaUI as omui | |
| from PyQt4.QtGui import QImage | |
| #from PySide.QtGui import QImage | |
| view = omui.M3dView.active3dView() | |
| width = view.portWidth() | |
| height = view.portHeight() | |
| img = om.MImage() | |
| #view.readColorBuffer(img, True) | |
| view.readColorBuffer(img, False) | |
| ptr = ctypes.cast(img.pixels().__long__(), ctypes.POINTER(ctypes.c_char)) | |
| ptrAsStr = ctypes.string_at(ptr, width * height * 4) | |
| qimg = QImage(ptrAsStr, width, height, QImage.Format_ARGB32) | |
| #qimg = qimg.rgbSwapped().mirrored(horizontal=False, vertical=True) | |
| qimg = qimg.mirrored(horizontal=False, vertical=True) | |
| qimg.save('C:/screenshot.png') | |
| ''' | |
| #convert to QPixmap | |
| from PyQt4.QtGui import QPixmap | |
| #from PySide.QtGui import QPixmap | |
| #qpix = QPixmap().convertFromImage(qimg) | |
| qpix = QPixmap().fromImage(qimg) | |
| qpix.save('C:/screenshot.png', 'png') | |
| ''' | |
| ''' | |
| #------------------------------ | |
| #grab frame buffer to MImage | |
| #------------------------------ | |
| import maya.OpenMaya as om | |
| import maya.OpenMayaUI as omui | |
| view = omui.M3dView.active3dView() | |
| img = om.MImage() | |
| view.readColorBuffer(img, True) | |
| img.writeToFile('C:/screenshot.png', 'png') | |
| ''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment