本文整理汇总了Python中surface.Surface.createGraphics方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.createGraphics方法的具体用法?Python Surface.createGraphics怎么用?Python Surface.createGraphics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类surface.Surface
的用法示例。
在下文中一共展示了Surface.createGraphics方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scale
# 需要导入模块: from surface import Surface [as 别名]
# 或者: from surface.Surface import createGraphics [as 别名]
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
示例2: rotate
# 需要导入模块: from surface import Surface [as 别名]
# 或者: from surface.Surface import createGraphics [as 别名]
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