本文整理汇总了Python中gi.repository.GdkPixbuf.Pixbuf.new方法的典型用法代码示例。如果您正苦于以下问题:Python Pixbuf.new方法的具体用法?Python Pixbuf.new怎么用?Python Pixbuf.new使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GdkPixbuf.Pixbuf
的用法示例。
在下文中一共展示了Pixbuf.new方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from gi.repository.GdkPixbuf import Pixbuf [as 别名]
# 或者: from gi.repository.GdkPixbuf.Pixbuf import new [as 别名]
def __init__(self, data, size, palette):
if not data:
# dummy image
self.pixbuf = Pixbuf.new(Colorspace.RGB, False, 8,
size[0] * 8 * 2, size[1] * 8 * 2)
self.pixbuf.fill(0xAAAAAAFF)
return
# slice into blocks
blocks = cut(data, BLOCK)
# slice block content
blocks = [cut(b, ROW) for b in blocks]
# rearrange into blockrows (y/x coordinates)
blocks = cut(blocks, size[0])
bytestring = []
# for each block row
for y in range(0, size[1]):
# for each final row
for i in range(0, int(BLOCK / ROW)):
# for each block column
for x in range(0, size[0]):
r = blocks[y][x][i]
# extract pixels from rows
for j in range(4):
bytestring.append(r[j] & 0x0F) # first (....AAAA)
bytestring.append(r[j] >> 4) # second (BBBB....)
# apply palette
result = []
for i in bytestring:
result += palette.colors[i]
# get result in binary format
result = b''+bytearray(result)
# create image
self.pixbuf = Pixbuf.new_from_data(
result, 0, False, 8,
8 * size[0], 8 * size[1], 8 * size[0] * 3, None, None)
self.pixbuf = self.pixbuf.scale_simple(
8 * size[0] * 2, 8 * size[1] * 2, InterpType.NEAREST)
示例2: image
# 需要导入模块: from gi.repository.GdkPixbuf import Pixbuf [as 别名]
# 或者: from gi.repository.GdkPixbuf.Pixbuf import new [as 别名]
window.set_size_request(500, 500)
## Add a row without own image (easy)
treestore.append(None, [None, "data without own image"])
## Add a row with a stock icon (also easy)
iconpixbuf = Gtk.IconTheme.get_default().load_icon("folder", 16, 0)
treestore.append(None, [iconpixbuf, "data with a stock icon"])
## Add a row with an image from disk (still easy, uncomment if you have a suitable image file)
#loadedpixbuf = Pixbuf.new_from_file_at_size("../../img/logo.png", 125, 125)
#treestore.append(None, [loadedpixbuf, "data with a custom image from disk"])
## Add a row with a flat-painted image (easy, but not always useful...)
from gi.repository import Gtk, Gdk
filledpixbuf = Pixbuf.new(Colorspace.RGB, True, 8, 16, 16) ## In fact, it is RGBA
filledpixbuf.fill(0xff9922ff)
treestore.append(None, [filledpixbuf, "data with a custom color filled image"])
px = PixbufLoader.new_with_type('pnm')
#color = b'\xee\xff\x2d'
#px.write(b'P6\n\n1 1\n255\n' + color)
#px.write(color)
iconpnm = b"""P2 24 7 25
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0