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