本文整理汇总了Python中qtpy.QtGui.QPixmap.fromImage方法的典型用法代码示例。如果您正苦于以下问题:Python QPixmap.fromImage方法的具体用法?Python QPixmap.fromImage怎么用?Python QPixmap.fromImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtGui.QPixmap
的用法示例。
在下文中一共展示了QPixmap.fromImage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _set_pixmap_from_array
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import fromImage [as 别名]
def _set_pixmap_from_array(self, arr):
bpl = arr.strides[0]
is_rgb = len(arr.shape) == 3
if is_rgb and arr.dtype == np.uint8:
format = QImage.Format_RGB32
image = QImage(arr.data, self.camera.width, self.camera.height, bpl, format)
elif not is_rgb and arr.dtype == np.uint8:
# TODO: Somehow need to make sure data is ordered as I'm assuming
format = QImage.Format_Indexed8
image = QImage(arr.data, self.camera.width, self.camera.height, bpl, format)
self._saved_img = arr
elif not is_rgb and arr.dtype == np.uint16:
if not self._cmax:
self._cmax = arr.max() # Set cmax once from first image
arr = scipy.misc.bytescale(arr, self._cmin, self._cmax)
format = QImage.Format_Indexed8
w, h = self.camera.width, self.camera.height
image = QImage(arr.data, w, h, w, format)
self._saved_img = arr # Save a reference to keep Qt from crashing
else:
raise Exception("Unsupported color mode")
self.setPixmap(QPixmap.fromImage(image))
pixmap_size = self.pixmap().size()
if pixmap_size != self.size():
self.setMinimumSize(self.pixmap().size())
示例2: __init__
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import fromImage [as 别名]
def __init__(self, parent, arr):
QLabel.__init__(self)
# we need to hold a reference to
# arr because QImage doesn't copy the data
# and the buffer must be alive as long
# as the image is alive.
self.arr = arr
# we also need to pass in the row-stride to
# the constructor, because we can't guarantee
# that every row of the numpy data is
# 4-byte aligned. Which Qt would require
# if we didn't pass the stride.
self.img = QImage(arr.data, arr.shape[1], arr.shape[0],
arr.strides[0], QImage.Format_RGB888)
self.pm = QPixmap.fromImage(self.img)
self.setPixmap(self.pm)
self.setAlignment(QtCore.Qt.AlignTop)
self.setMinimumSize(100, 100)
示例3: resizeEvent
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import fromImage [as 别名]
def resizeEvent(self, evt):
width = self.width()
pm = QPixmap.fromImage(self.img)
self.pm = pm.scaledToWidth(width)
self.setPixmap(self.pm)
示例4: update_image
# 需要导入模块: from qtpy.QtGui import QPixmap [as 别名]
# 或者: from qtpy.QtGui.QPixmap import fromImage [as 别名]
def update_image(self):
width = self.width()
pm = QPixmap.fromImage(self.img)
pm = pm.scaledToWidth(width)
self.setPixmap(pm)