[Qgis-developer] Re: How to use QPixmap argument in saveAsImage()

pfth pfth at gmx.de
Thu Mar 4 06:46:20 EST 2010


Hi Martin!


Martin Dobias wrote:
> 
> Well, it's hard to help you without any further information.
> - what qgis version? what platform?
> - can you provide backtrace of the segfaults?
> - have you tried to run the code from python console?
> 

Sorry for my imprecise question...

I am working with QGis 1.4.0 Enceladus with code version 12728 on a Windows
XP Professional machine (Intel Core2 Duo E8400 at 3,00Mhz, 3,46 GB RAM). The
error message I am getting seems to be the standard system message:

qgis.exe has encountered a problem and needs to close.

When I click on "further information", I get:
AppName: qgis.exe
AppVer: 0.0.0.0
ModName: qgis_core.dll
ModVer: 0.0.0.0
Offset: 00068a61
Exception Information: Code: 0xc0000005

The QGis Project consists of some orthophotos and overlaying shapefiles.

When I run your sourcecode within the Python console, it does not raise any
error messages when it is started for the first time! When I start it a
scond time, the same error occurs like when running the plugin... 

Sometimes the plugin saves the image and crashes afterwards. Some other
times it does not even save the file, it crashes at an earlier stage. I
tried to check for the problematic line of the code. So i commented out the
lines from the bottom up. The most problematic line seems to be
"c.addItem(composerMap)"... 

Could it be there are some problems with some unused or not correctly freed
objects...? Any ideas?

Thanks in advance
Thomas

PS: This is my uses block:

from PyQt4.QtCore import * 
from PyQt4.QtGui import *
from qgis.core import *
from qgis.utils import iface

And this is my run() function (__init__, initGui, unload are not changed):

  # run method that performs all the real work
  def run(self): 
    # set up composition
    mapRenderer = iface.mapCanvas().mapRenderer()
    c = QgsComposition(mapRenderer)
    c.setPlotStyle(QgsComposition.Print)

    dpi = c.printResolution()
    dpmm = dpi / 25.4
    width = int(dpmm * c.paperWidth())
    height = int(dpmm * c.paperHeight())

    # add a map to the composition
    x, y = 0, 0
    w, h = c.paperWidth(), c.paperHeight()
    composerMap = QgsComposerMap(c, x,y,w,h)
    c.addItem(composerMap)

    # create output image and initialize it
    image = QImage(QSize(width, height), QImage.Format_ARGB32)
    image.setDotsPerMeterX(dpmm * 1000)
    image.setDotsPerMeterY(dpmm * 1000)
    image.fill(0)

    # render the composition
    imagePainter = QPainter(image)
    sourceArea = QRectF(0, 0, c.paperWidth(), c.paperHeight())
    targetArea = QRectF(0, 0, width, height)
    c.render(imagePainter, targetArea, sourceArea)
    imagePainter.end()

    image.save("out.png", "png") 

-- 
View this message in context: http://n2.nabble.com/How-to-use-QPixmap-argument-in-saveAsImage-tp4457393p4673739.html
Sent from the qgis-developer mailing list archive at Nabble.com.


More information about the Qgis-developer mailing list