本文整理汇总了Python中PySide.QtGui.QImage.copy方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.copy方法的具体用法?Python QImage.copy怎么用?Python QImage.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QImage
的用法示例。
在下文中一共展示了QImage.copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: capture
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import copy [as 别名]
def capture(self, region=None, selector=None,
format=QImage.Format_ARGB32_Premultiplied):
"""Returns snapshot as QImage.
:param region: An optional tuple containing region as pixel
coodinates.
:param selector: A selector targeted the element to crop on.
:param format: The output image format.
"""
if region is None and selector is not None:
region = self.region_for_selector(selector)
if region:
x1, y1, x2, y2 = region
w, h = (x2 - x1), (y2 - y1)
image = QImage(QSize(x2, y2), format)
painter = QPainter(image)
self.main_frame.render(painter)
painter.end()
image = image.copy(x1, y1, w, h)
else:
self.main_frame.setScrollBarPolicy(QtCore.Qt.Vertical,
QtCore.Qt.ScrollBarAlwaysOff)
self.main_frame.setScrollBarPolicy(QtCore.Qt.Horizontal,
QtCore.Qt.ScrollBarAlwaysOff)
self.page.setViewportSize(self.main_frame.contentsSize())
image = QImage(self.page.viewportSize(), format)
painter = QPainter(image)
self.main_frame.render(painter)
painter.end()
return image
示例2: copy_to_clipboard
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import copy [as 别名]
def copy_to_clipboard(plot):
# pass
# @staticmethod
# def wx_copy_to_clipboard(plot):
# # WX specific, though QT implementation is similar using
# # QImage and QClipboard
# import wx
#
width, height = plot.outer_bounds
#
gc = PlotGraphicsContext((width, height), dpi=72)
backbuffer = plot.use_backbuffer
plot.use_backbuffer = False
gc.render_component(plot)
plot.use_backbuffer = backbuffer
#
# # Create a bitmap the same size as the plot
# # and copy the plot data to it
bmp = gc.bmp_array
if gc.format().startswith('bgra'):
bmp_rgba = bmp[:,:,[2,1,0,3]]
else:
bmp_rgba = bmp
bitmap=QImage(bmp_rgba.tostring(),width,height, PySide.QtGui.QImage.Format_RGB32)
if QApplication.clipboard():
QApplication.clipboard().setImage(bitmap.copy())
else:
PySide.QtGui.QMessageBox("Unable to open the clipboard.", "Error")
示例3: takeScreenshot
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import copy [as 别名]
def takeScreenshot(self):
[x,y,width,height] = self.image_crop
frame = self.page().mainFrame()
size = frame.contentsSize()
size.setWidth(1000)
size.setHeight(2000)
self.page().setViewportSize(size)
image = QImage(self.page().viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
frame.render(painter)
painter.end()
image1 = image.copy(x,y,width,height)
image1.save(self.fileName)
self.finished = True
示例4: project
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import copy [as 别名]
def project(screen, size, tiles, rotate, tilecolor, backcolor = None):
backcolor = Qt.white if backcolor is None else backcolor
res = len(tiles)
template = QImage(size[0]/res, 2*size[1]/res, QImage.Format_RGB32)
screen.setBrush(backcolor)
screen.drawEllipse(0, 0, res * template.width()/2, res * template.height()/2)
screen.drawEllipse(res * template.width()/2, 0, res * template.width()/2, res * template.height()/2)
for y in range(res):
r = rotate
o = (r + 90) * len(tiles[y])/360
# draw each hemisphere from outside to center
sections = [[] for s in range(4)]
i = 0
while i < len(tiles[y]) and tiles[y][i].vector[0] < 0:
sections[0].append(i)
i += 1
while i < len(tiles[y]) and tiles[y][i].vector[0] > tiles[y][i-1].vector[0]:
sections[1].append(i)
i += 1
while i < len(tiles[y]) and tiles[y][i].vector[0] > 0:
sections[2].append(i)
i += 1
while i < len(tiles[y]):
sections[3].append(i)
i += 1
for x in sections[0] + list(reversed(sections[3])) + sections[2] + list(reversed(sections[1])):
block = template.copy()
xo = x + o
if xo > len(tiles[y])-1:
xo -= len(tiles[y])
elif xo < 0:
xo += len(tiles[y])
v = tiles[y][x].vector
sx, sy = [(v[i+1]+1)/2 for i in range(2)]
sx = 1 + (sx if v[0] > 0 else -sx)
block.fill(tilecolor(tiles[y][xo]).rgb())
screen.drawImage(sx*res*block.width()/2, sy*res*block.height()/2, block)
示例5: copy_to_clipboard
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import copy [as 别名]
def copy_to_clipboard(plot):
width, height = plot.outer_bounds
gc = PlotGraphicsContext((width, height), dpi=72)
backbuffer = plot.use_backbuffer
plot.use_backbuffer = False
gc.render_component(plot)
plot.use_backbuffer = backbuffer
# Create a bitmap the same size as the plot
# and copy the plot data to it
bmp = gc.bmp_array
cache_bmp = bmp.tobytes()
bitmap = QImage(cache_bmp, width+1, height+1, QImage.Format_RGB32)
if QApplication.clipboard():
QApplication.clipboard().setImage(bitmap.copy(), QClipboard.Clipboard)
else:
PySide.QtGui.QMessageBox("Unable to open the clipboard.", "Error")
示例6: numpy_to_qimage
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import copy [as 别名]
def numpy_to_qimage(array):
""" Returns QImage from an RGB array ."""
rows, cols, channels = array.shape
array4 = np.zeros((rows, cols, 4), dtype=np.uint8)
array4[..., 0:3] = array
array4[..., 3] = 255
c0 = array[..., 0].copy()
c2 = array[..., 2].copy()
array4[..., 0] = c2
array4[..., 2] = c0
string = array4.tostring()
img = QImage(string, cols, rows, QImage.Format_ARGB32)
# On windows, img `img` holds a reference to `string` and behaves wrongly
# when the string goes out of scope.
return img.copy()
示例7: from_opencv
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import copy [as 别名]
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()