def scale(self, surface, size, dest=None): """ Return Surface resized by the given size. An optional destination surface can be provided. """ if not dest: surf = Surface(size, BufferedImage.TYPE_INT_ARGB) else: surf = dest g2d = surf.createGraphics() g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR) g2d.drawImage(surface, 0, 0, size[0], size[1], None) g2d.dispose() return surf
def rotate(self, surface, angle): """ Return Surface rotated by the given angle. """ theta = angle*self.deg_rad width_i = surface.getWidth() height_i = surface.getHeight() cos_theta = math.fabs( math.cos(theta) ) sin_theta = math.fabs( math.sin(theta) ) width_f = int( (width_i*cos_theta)+(height_i*sin_theta) ) height_f = int( (width_i*sin_theta)+(height_i*cos_theta) ) surf = Surface((width_f,height_f), BufferedImage.TYPE_INT_ARGB) at = AffineTransform() at.rotate(-theta, width_f/2, height_f/2) g2d = surf.createGraphics() ot = g2d.getTransform() g2d.setTransform(at) g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR) g2d.drawImage(surface, (width_f-width_i)//2, (height_f-height_i)//2, None) g2d.setTransform(ot) g2d.dispose() return surf
def rotate(self, surface, angle): """ Return Surface rotated by the given angle. """ theta = angle * self.deg_rad width_i = surface.getWidth() height_i = surface.getHeight() cos_theta = math.fabs(math.cos(theta)) sin_theta = math.fabs(math.sin(theta)) width_f = int((width_i * cos_theta) + (height_i * sin_theta)) height_f = int((width_i * sin_theta) + (height_i * cos_theta)) surf = Surface((width_f, height_f), BufferedImage.TYPE_INT_ARGB) at = AffineTransform() at.rotate(-theta, width_f / 2, height_f / 2) g2d = surf.createGraphics() ot = g2d.getTransform() g2d.setTransform(at) g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR) g2d.drawImage(surface, (width_f - width_i) // 2, (height_f - height_i) // 2, None) g2d.setTransform(ot) g2d.dispose() return surf