本文整理汇总了Python中PySide.QtGui.QImage.pixel方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.pixel方法的具体用法?Python QImage.pixel怎么用?Python QImage.pixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QImage
的用法示例。
在下文中一共展示了QImage.pixel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImagenQImage
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import pixel [as 别名]
class ImagenQImage(BaseImagen):
def __init__(self):
super(ImagenQImage, self).__init__()
self.mode = "No implementado"
@property
def size(self):
return (self.img.width(), self.img.height())
def fromfile(self, filename):
self.img = QImage(filename)
def from_instance(self, qimage):
self.img = qimage
def empty(self, size, mode=QImage.Format_RGB888):
self.img = QImage(size[0], size[1], mode)
self.img.fill(qRgb(0,0,0))#Rellenamos la imagen con negro
def getpixel(self, xy):
color = self.img.pixel(xy[0], xy[1])
return (qRed(color), qGreen(color), qBlue(color))
def putpixel(self, xy, value):
self.img.setPixel(xy[0], xy[1], qRgb(value[0], value[1], value[2]))
def get_img(self):
return self.img
def save(self, filename):
self.img.save(filename, format="BMP", quality=100)
def from_opencv(self, img_opencv):
dst = cv2.cvtColor(img_opencv, cv2.COLOR_BGR2RGB)
qim = QImage(dst.data, dst.shape[1], dst.shape[0], dst.strides[0], QImage.Format_RGB888)
self.img = qim.copy()
示例2: QCoreApplication
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import pixel [as 别名]
from PySide.QtCore import QCoreApplication
from PySide.QtGui import QImage
if __name__ == "__main__":
app = QCoreApplication([])
img = QImage("lenna.png")
w, h = img.size().width(), img.size().width()
for p in ((x, y) for x in range(w) for y in range(h)):
colour = img.pixel(p[0], p[1]) # AARRGGBB
r = (colour >> 16) & 0xFF
g = (colour >> 8) & 0xFF
b = colour & 0xFF
avg = round((r + g + b) / 3) # Naïve method (no colour weighting)
new_colour = 0xff000000 + (avg << 16) + (avg << 8) + avg
img.setPixel(p[0], p[1], new_colour)
img.save("output.png")