本文整理汇总了Python中PySide.QtGui.QImage.setPixel方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.setPixel方法的具体用法?Python QImage.setPixel怎么用?Python QImage.setPixel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QImage
的用法示例。
在下文中一共展示了QImage.setPixel方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_red_image
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import setPixel [as 别名]
def create_red_image(self, img):
new_img = QImage(img)
for x in range(0, img.width()):
for y in range(0, img.height()):
pix = img.pixel(x, y)
r = pix & 0xFF
g = (pix >> 8) & 0xFF
b = (pix >> 16) & 0xFF
alpha_mask = pix & 0xFF000000
new_img.setPixel(x, y, (alpha_mask | ((r + g + b) / 3)))
return new_img
示例2: setSettings
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import setPixel [as 别名]
def setSettings(self):
"""Set color, verbosity and logging options."""
self.logDock.setBgColor(self.config.get('Appearance', 'log_bg_color'))
image = QImage(10, 10, QImage.Format_RGB32)
image.fill(QColor(self.config.get('Appearance', 'circ_bg_color')))
image.setPixel(0, 0, QColor(0, 0, 0).rgb())
self.view.scene().setBackgroundBrush(QBrush(QPixmap.fromImage(image)))
Plug.setInputVerbose = self.config.getboolean(
'LogVerbosity', 'input_chang')
Plug.setOutputVerbose = self.config.getboolean(
'LogVerbosity', 'output_chang')
Plug.connectVerbose = self.config.getboolean(
'LogVerbosity', 'conn_discon_io')
Plug.addPlugVerbose = self.config.getboolean(
'LogVerbosity', 'adding_io')
Circuit.addCircuitVerbose = self.config.getboolean(
'LogVerbosity', 'adding_circ')
Circuit.removePlugVerbose = self.config.getboolean(
'LogVerbosity', 'removing_io')
Circuit.removeCircuitVerbose = self.config.getboolean(
'LogVerbosity', 'removing_circ')
Circuit.detailedRemoveVerbose = self.config.getboolean(
'LogVerbosity', 'detailed_rm')
ClockThread.spd = self.config.getfloat(
'Clock', 'speed')
if self.config.getboolean('LogHandlers', 'gui'):
log.addHandler(self.logDock.handler)
else:
log.removeHandler(self.logDock.handler)
if self.config.getboolean('LogHandlers', 'stdout'):
log.addHandler(stdoutHandler)
else:
log.removeHandler(stdoutHandler)
if self.config.getboolean('LogHandlers', 'file'):
log.addHandler(fileHandler)
else:
log.removeHandler(fileHandler)
示例3: ImagenQImage
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import setPixel [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()
示例4: QCoreApplication
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import setPixel [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")
示例5: Render
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import setPixel [as 别名]
class Render():
'''Transform the numpy data into a renderable image suitable for screen'''
def __init__( self, world ):
self.world = world
for k in self.world:
exec( 'self.' + k + ' = self.world[k]' )
self.width, self.height = self.elevation.shape
self.image = QImage( self.width, self.height, QImage.Format_RGB32 )
self.image.fill(QtGui.QColor(0,0,0))
def hex2rgb( self, hexcolor ):
r = ( hexcolor >> 16 ) & 0xFF;
g = ( hexcolor >> 8 ) & 0xFF;
b = hexcolor & 0xFF;
return [r, g, b]
def rgb2hex( self, rgb ):
assert( len( rgb ) == 3 )
return '#%02x%02x%02x' % rgb
def convert( self, mapType, seaLevel = None ):
if seaLevel:
seaLevel /= 100.0 # reduce to 0.0 to 1.0 range
background = []
if mapType == "heightmap":
heightmap = self.elevation * 255 # convert to greyscale
for x in range( self.width ):
for y in range( self.height ):
gValue = heightmap[x, y]
self.image.setPixel( x, y, QtGui.QColor( gValue, gValue, gValue ).rgb() )
elif mapType == "sealevel":
for x in range( self.width ):
for y in range( self.height ):
elevation = self.elevation[x, y]
gValue = elevation * 255
if elevation <= seaLevel:
self.image.setPixel( x, y, QtGui.QColor( 0, 0, gValue ).rgb() )
else:
self.image.setPixel( x, y, QtGui.QColor( gValue, gValue, gValue ).rgb() )
elif mapType == "elevation":
for x in range( self.width ):
for y in range( self.height ):
elevation = self.elevation[x, y]
if elevation <= seaLevel:
if elevation < seaLevel/4.0:
self.image.setPixel( x, y, COLOR_DEEPSEA )
elif elevation < seaLevel/2.0:
self.image.setPixel( x, y, COLOR_SEA )
else:
self.image.setPixel( x, y, COLOR_BLUE )
else:
if elevation < 0.65:
self.image.setPixel( x, y, COLOR_GRASSLAND )
elif elevation < 0.95:
self.image.setPixel( x, y, COLOR_HILLS )
else:
self.image.setPixel( x, y, COLOR_WHITE )
elif mapType == "heatmap":
for x in range( self.width ):
for y in range( self.height ):
gValue = self.temperature[x, y]
self.image.setPixel( x, y, QtGui.QColor( gValue * 255, gValue * 128, ( 1 - gValue ) * 255 ).rgb() )
elif mapType == "rawheatmap":
temperature = self.temperature * 255 # convert to greyscale
for x in range( self.width ):
for y in range( self.height ):
gValue = temperature[x, y]
self.image.setPixel( x, y, QtGui.QColor( gValue, gValue, gValue ).rgb() )
elif mapType == 'windmap':
for x in range( self.width ):
for y in range( self.height ):
gValue = self.wind[x, y]
self.image.setPixel( x, y, QtGui.QColor( 0, gValue * 255, 0 ).rgb() )
elif mapType == 'rainmap':
for x in range( self.width ):
for y in range( self.height ):
gValue = self.rainfall[x, y]
self.image.setPixel( x, y, QtGui.QColor( gValue * 100, gValue * 100, gValue * 255 ).rgb() )
elif mapType == 'windandrainmap':
for x in range( self.width ):
for y in range( self.height ):
rain = int( 255 * min( self.wind[x, y], 1.0 ) )
wind = int( 255 * min( self.rainfall[x, y], 1.0 ) )
self.image.setPixel( x, y, QtGui.QColor( 0, wind, rain ).rgb() )
elif mapType == 'drainagemap':
drainage = self.drainage * 255 # convert to greyscale
for x in range( self.width ):
for y in range( self.height ):
gValue = drainage[x, y]
#.........这里部分代码省略.........