I would like to take a screenshot of my QGIS area, which I am working on.
It does look pretty much as you can see below:
I would like to grab only the visible area of my map. I am not talking about map canvas, as mentioned here:
Save map canvas as image with Python in QGIS
PyQGIS make screenshot of mapCanvas after setExtent is called
Saving Map Canvas as PNG with transparent background programmatically with QGIS?
I simply want to have an option to grab the screen from my QGIS working area defined by it visible bounds (after dock windows visible).
I tried some of the codes, but they didn't work:
mainPath = 'C:\\Users\\mk\\Desktop\\AX\\Pre survey\\Tyton\\' filename = 'StrandAAA' imageType = "png" imageWidth_mm = 400 imageHeight_mm = 160 dpi = 300 mapRenderer = iface.mapCanvas().mapRenderer() c = QgsComposition(mapRenderer) c.setPlotStyle(QgsComposition.Print) c.setPaperSize(400, 160) x, y = 0, 0 w, h = c.paperWidth(), c.paperHeight() composerMap = QgsComposerMap(c, x ,y, w, h) c.addItem(composerMap) # get all items and disable the backgrounds itemList = c.items() c.removeItem(itemList) c.removeItem(itemList) itemList.setBackgroundEnabled(False) itemList.setBackgroundEnabled(False) # add them to the composition c.addItem(itemList) c.addItem(itemList) c.refreshItems() c.refreshDataDefinedProperty(QgsComposerObject.AllProperties) c.setPrintResolution(dpi) dpmm = dpi / 25.4 width = int(dpmm * c.paperWidth()) height = int(dpmm * c.paperHeight()) # create output image and initialize it # image = QImage(QSize(width, height), QImage.Format_ARGB32) image = QImage(QSize(width, height), QImage.Format_ARGB32_Premultiplied) image.setDotsPerMeterX(dpmm * 1000) image.setDotsPerMeterY(dpmm * 1000) #image.fill(0) imagePainter = QPainter(image) # This part does not seem to have any effect #brush = QBrush(Qt.BrushStyle(0)) # transparent brush # #imagePainter.setBackgroundMode(0) #c.setBackgroundBrush(brush) c.renderPage( imagePainter, 0 ) imagePainter.end() imageFilename = mainPath + filename + '.' + imageType image.save(imageFilename, imageType) print 'image saved' print 'done
but it didn't work, the same as:
vlayer.select(ID) qgis.utils.iface.actionZoomToSelected().trigger() vlayer.deselect(ID) qgis.utils.iface.mapCanvas().saveAsImage('C:\\Users\\mk\\Desktop\\AX\\Pre survey\\Tyton\\feature.png')
The solution is shown on the YT channel here also wasn't successful
I think I am closer to this solution:
Is it possible to take automatically a "screenshot" of my selected feature in QGIS using Python?
butt instead of selected feature I need the visible map area
The typical solution for taking a screenshot in Windows doesn't solve my request
although in Pyscreenshot v2.3 I can define the rough bounds of my screen and capture them, how about if I change my QGIS window to another place
Is there an option to capture the screenshot of the visible map in QGIS both by using PyGIS or maybe not programmatically (GRASS or sth?)