def _save_image(self): file_name, _ = QFileDialog.getSaveFileName( self._widget, self.tr('Save as image'), 'rospackgraph.png', self.tr('Image (*.bmp *.jpg *.png *.tiff)')) if file_name is None or file_name == '': return img = QImage((self._scene.sceneRect().size() * 2.0).toSize(), QImage.Format_ARGB32_Premultiplied) painter = QPainter(img) painter.setRenderHint(QPainter.Antialiasing) self._scene.render(painter) painter.end() img.save(file_name)
def _save_svg(self): file_name, _ = QFileDialog.getSaveFileName( self._widget, self.tr('Save as SVG'), 'rospackgraph.svg', self.tr('Scalable Vector Graphic (*.svg)')) if file_name is None or file_name == '': return generator = QSvgGenerator() generator.setFileName(file_name) generator.setSize((self._scene.sceneRect().size() * 2.0).toSize()) painter = QPainter(generator) painter.setRenderHint(QPainter.Antialiasing) self._scene.render(painter) painter.end()
def renderSVGQt(contents, outfn, size): """Has font problems, letter spacing too broad, version number cropped (compared to inkscape output). Unused, but kept for reference. """ from gui.qt import QtCore, QtSvg, QtGui from QtSvg import QSvgRenderer from QtCore import QByteArray from QtGui import QImage, QPainter, QApplication app = QApplication([]) svg = QSvgRenderer(QByteArray(contents.encode("utf-8"))) img = QImage(size, size, QImage.Format_ARGB32) painter = QPainter(img) svg.render(painter) painter.end() img.save(outfn)