I copied and pasted your code into a new script, and get the same result - when I lift my finger off at the end of a stroke, the alpha value of the whole stroke changes (gets lighter).
I am running the latest version of Pythonista (3.2) using python 3.6 on a 10.5” iPad Pro with iOS 11.2
I have modified the Sketch.py code to draw a succession of ovals instead of using path.stroke(), with the intention of using the pencil pressure to change the alpha at different points along the path. In the code below I have kept it constant for simplicity. But the alpha value does not seem to be captured correctly in ctx.get_image(), causing it to change when path_action() is called at the end of the path. Just add the code below to the Sketch.py example, and change the definition in touch_began() to self.path = MyPath() to see the problem when you lift the pencil/finger at the end of the stroke.
import math def distanceBetween(point1, point2): return math.sqrt((point2 - point1)**2 + (point2 - point1)**2) def angleBetween(point1, point2): return math.atan2( point2 - point1, point2 - point1 ) class MyPath(): def move_to(self,x,y): self.path = [(x,y)] def line_to(self,x,y): self.path.append((x,y)) def stroke(self): w = 20 ui.set_alpha(0.006) lastPoint = self.path for i in range(1,len(self.path)): currentPoint = self.path[i] dist = distanceBetween(lastPoint, currentPoint) angle = angleBetween(lastPoint, currentPoint) for j in range(int(dist)): x = lastPoint + (math.sin(angle) * j) y = lastPoint + (math.cos(angle) * j) circle = ui.Path.oval(x, y, w, w) circle.fill() lastPoint = currentPoint