def draw_image(self, painter, canvasRect, srcRect, dstRect, xMap, yMap): # normally we use this method indirectly from quiqwt which takes the burden of constructing # the right parameters. if we want to call this method manually, eg for painting on on a # QPixmap for saving the image, we just use the last set of parmeters passed to this # method, this is much easier than constructing the params seperatly, and so we get the # exact same result as we see on screen: self.last_canvas_rect = canvasRect self.last_src_rect = srcRect self.last_dst_rect = dstRect self.last_xmap = xMap self.last_ymap = yMap rtmin, mzmax, rtmax, mzmin = srcRect x1, y1 = canvasRect.left(), canvasRect.top() x2, y2 = canvasRect.right(), canvasRect.bottom() NX = x2 - x1 NY = y2 - y1 rtmin, mzmax, rtmax, mzmin = srcRect image = self.compute_image(0, NX, NY, rtmin, rtmax, mzmin, mzmax)[::-1, :] image2 = self.compute_image(1, NX, NY, rtmin, rtmax, mzmin, mzmax)[::-1, :] dilated = dilate(image.astype(np.int32), mzmax, mzmin) dilated2 = dilate(image2.astype(np.int32), mzmax, mzmin) self.data = np.zeros_like(dilated, dtype=np.uint32)[::-1, :] # add image as rgb(255, 255, 0): first we add red, then green which yields yellow: self.data += dilated * 256 * 256 # plus red: self.data += dilated * 256 # add image2 as rgb(0, 0, 256) which is blue: self.data += dilated2 self.data |= 255 << 24 self.bounds = QRectF(rtmin, mzmin, rtmax - rtmin, mzmax - mzmin) RGBImageItem.draw_image(self, painter, canvasRect, srcRect, dstRect, xMap, yMap)