Bug report #21295

Rendering with QImage.Format_Indexed8 produces blank output

Added by Alexey T about 1 year ago. Updated about 1 year ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Unknown
Affected QGIS version:3.4.4 Regression?:No
Operating System:win7 Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:29113

Description

I'm trying to make 8bit PNG tiles, so I'm using this sequence

setting = QgsMapSettings()
settings.setOutputImageFormat(QImage.Format_Indexed8)

job = QgsMapRendererParallelJob(self.settings)
job.start()
job.waitForFinished()
image = job.renderedImage()
image.save('path', 'png', -1)

resulting in blank (white) output tiles

using QImage.Format_ARGB32_Premultiplied works as expected

History

#1 Updated by Marco Hugentobler about 1 year ago

  • Status changed from Open to Closed

The Qt documentation says:
Warning: Painting on a QImage with the format QImage::Format_Indexed8 is not supported

Instead you could render into a ARGB32_Premultiplied image and convert it to Indexed8 afterwards:

setting = QgsMapSettings()
settings.setOutputImageFormat(Format_ARGB32_Premultiplied)
job = QgsMapRendererParallelJob(self.settings)
job.start()
job.waitForFinished()
image = job.renderedImage()
image8Bit = image.convertToFormat( QImage.Format_Indexed8 )
image8Bit.save('path')

Also available in: Atom PDF