PyQt, Add blank space to Pixmap (copy one Pixmap into a blank Pixmat of higher resolution)

18 Views Asked by At

Original image

input

New Image

ouput

Problem Statement

Suppose the original pixmap is of 300x300, and I want it to be extended in y axis by 200 pixels, new image being 300x500 pixels. How can I do it?

# Current
pixmap = QtGui.QPixmap(WIDTH, HEIGHT)
pixmap.fill(Qt.transparent)
self.setPixmap(pixmap)

# New
pixmap = self.pixmap().scaled(
            WIDTH,
            NEW_HEIGHT,
            Qt.IgnoreAspectRatio,
            Qt.SmoothTransformation)
self.setPixmap(pixmap)

Things I tried:

  1. Rescaling, but it only stretches the whole image to that resolution and distorts the image
  2. I can create a new blank canvas of the new resolution, and ask the user to redraw or rewrite on the canvas again but it will be very inconvinient

Application: I will be using this in my paint app, I am adding a scroll bar with my canvas, and with a button you can extend the canvas downwards and keep writing/drawing. The app is build on PyQt.

0

There are 0 best solutions below