Update: another way to get a screenshot of a rendered image, but directly in-memory instead of writing it to a file. You need to use PNMImage:
def renderToPNM(self):
### RENDER IMAGE
# Render the frame
self.base.graphicsEngine.renderFrame()
### FETCHING THE RENDERED IMAGE
# Prepare the variable that will store the frame image (in a PNMImage class, this is NOT a file format, but a convenient image manipulation class offered by Panda3D)
image = PNMImage()
# Set display region to the default
dr = base.camNode.getDisplayRegion(0)
# Store the rendered frame into the variable screenshot
dr.getScreenshot(image)
return image