def imprint(self, cr, xSz, ySz):
#Get the position on the cnavas.
ySt, xSt = self.pos_.y_asint() - self.imSt_.y_asint(), self.pos_.x_asint() - self.imSt_.x_asint()
yEn, xEn = ySt + self.ySz_, xSt + self.xSz_
#Get the data that can be pasted
y1, x1 = np.abs(min(0, ySt)), np.abs(min(0, xSt))
y2 = self.ySz_ - np.abs(min(0, ySz - yEn))
x2 = self.xSz_ - np.abs(min(0, xSz - xEn))
#Correct for positions on canvas
ySt, xSt = max(0, ySt), max(0, xSt)
yEn, xEn = min(ySz, yEn), min(xSz, xEn)
srcIm = np.zeros((ySz, xSz, 4), dtype=np.uint8)
srcIm[ySt:yEn, xSt:xEn,:] = self.data_.im[y1:y2, x1:x2]
surface = cairo.ImageSurface.create_for_data(srcIm,
cairo.FORMAT_ARGB32, xSz,ySz)
cr.set_source_surface(surface)
cr.rectangle(xSt, ySt, x2 - x1, y2 - y1)
cr.fill()
评论列表
文章目录