2
에 텍스트를 렌더링하는 방법
파이썬과 GDK 3.GdkPixbuf.Pixbuf
내가 시간 동안이 주제에 대한 정보를 원하시면 웹 검색 봤는데를 사용하여 Pixbuf에 텍스트를 추가하려고 노력하고 있어요 Pixbuf에서 카이로 컨텍스트를 만들어야 할 것 같습니다. 불행하게도, 나는 카이로와 제로 경험을 가지고,하지만 난이 코드 조각을 조립 할 수있었습니다 : 적어도 내 프로그램에 충돌이 발생하지 않습니다
from gi.repository import Gdk
def put_text(pixbuf, text, x, y):
#create a Gdk.Window
window_attr= Gdk.WindowAttr()
window_attr.width= pixbuf.get_width()
window_attr.height= pixbuf.get_height()
window_attr.window_type= Gdk.WindowType.OFFSCREEN
#~ window_attr.window_type= Gdk.WindowType.TEMP
window_attr.redirect= True
#~ window_attr.redirect= False
window= Gdk.Window(None, window_attr, Gdk.WindowAttributesType(0))
#make a cairo context from the window
context= Gdk.cairo_create(window)
Gdk.cairo_set_source_pixbuf(context, pixbuf, 0, 0)
#render text
context.move_to(x, y)
context.set_font_size(15)
context.show_text(text)
#get the resulting pixbuf
surface= context.get_target()
result= Gdk.pixbuf_get_from_surface(surface, 0, 0, surface.get_width(), surface.get_height())
#~ window.destroy()
return result
. 그러나 그것이 생산하는 pixbuf는 완전히 투명합니다. 아무도 내가 뭘 잘못하고 있는지 또는 이것을 할 수있는 더 좋은 방법이 있는지 말해 줄 수 있습니까?