def cairo_image_surface_from_image(image):
if image.mode != 'RGBA':
image = image.convert('RGBA')
width, height = image.size
stride = cairo.ImageSurface.format_stride_for_width(
cairo.FORMAT_ARGB32, width)
image_buffer = array.array('c')
image_buffer.fromstring(
image_rgba_to_bgra(
image.tostring()))
cairo_image = cairo.ImageSurface.create_for_data(
image_buffer, cairo.FORMAT_ARGB32, width, height, stride)
return cairo_image
评论列表
文章目录