我很难理解如何简单地用pyCairo旋转图像.
以下是我在这个例子基础上所做的工作:
image_surface = cairo.ImageSurface.create_from_png(image_path)
width = image_surface.get_width()
height = image_surface.get_height()
context = cairo.Context(cairo.ImageSurface (cairo.FORMAT_ARGB32, width, height))
context.translate(width*0.5, height*0.5)
context.rotate(45.0*math.pi/180.0)
context.scale(1.0, 1.0)
context.translate(-width*0.5, -height*0.5)
context.set_source_surface(image_surface, 0, 0)
context.paint()
image_surface.write_to_png(output_path)
输出图像与初始图像相同。我错过了什么?
发布于 2016-01-04 17:02:28
有两个问题:
cairo.ImageSurface
实例来编写新映像:
Cairo.ImageSurface=cairo.FORMAT_ARGB32(宽度、高度)上下文=cairo.Context(表面)(.)surface.write_to_png(output_path)context.scale
和context.translate
:
Context.translate(宽度*0.5,-height*0.5) context.scale(1.0,1.0)顺便说一下,应该重新计算新图像的宽度和高度。
https://stackoverflow.com/questions/34595604
复制相似问题