本文整理汇总了Python中AnyQt.QtGui.QPixmap.fromImage方法的典型用法代码示例。如果您正苦于以下问题:Python QPixmap.fromImage方法的具体用法?Python QPixmap.fromImage怎么用?Python QPixmap.fromImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtGui.QPixmap
的用法示例。
在下文中一共展示了QPixmap.fromImage方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_pixmap
# 需要导入模块: from AnyQt.QtGui import QPixmap [as 别名]
# 或者: from AnyQt.QtGui.QPixmap import fromImage [as 别名]
def set_pixmap(future, thumb=thumbnail):
if future.cancelled():
return
assert future.done()
if future.exception():
# Should be some generic error image.
pixmap = QPixmap()
thumb.setToolTip(thumb.toolTip() + "\n" +
str(future.exception()))
else:
pixmap = QPixmap.fromImage(future.result())
thumb.setPixmap(pixmap)
self._noteCompleted(future)
示例2: update_properties
# 需要导入模块: from AnyQt.QtGui import QPixmap [as 别名]
# 或者: from AnyQt.QtGui.QPixmap import fromImage [as 别名]
def update_properties(self):
## Mostly copied from OWScatterPlotGraph
if not self.plot():
return
if not self.rect:
x,y = self.axes()
self.rect = self.plot().data_rect_for_axes(x,y)
s = self.graph_transform().mapRect(self.rect).size().toSize()
if not s.isValid():
return
rx = s.width()
ry = s.height()
rx -= rx % self.granularity
ry -= ry % self.granularity
p = self.graph_transform().map(QPointF(0, 0)) - self.graph_transform().map(self.rect.topLeft())
p = p.toPoint()
ox = p.x()
oy = -p.y()
if self.classifier.classVar.is_continuous:
imagebmp = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale)
palette = [qRgb(255.*i/255., 255.*i/255., 255-(255.*i/255.)) for i in range(255)] + [qRgb(255, 255, 255)]
else:
imagebmp, nShades = orangeom.potentialsBitmap(self.classifier, rx, ry, ox, oy, self.granularity, self.scale, self.spacing)
palette = []
sortedClasses = get_variable_values_sorted(self.classifier.domain.classVar)
for cls in self.classifier.classVar.values:
color = self.plot().discPalette.getRGB(sortedClasses.index(cls))
towhite = [255-c for c in color]
for s in range(nShades):
si = 1-float(s)/nShades
palette.append(qRgb(*tuple([color[i]+towhite[i]*si for i in (0, 1, 2)])))
palette.extend([qRgb(255, 255, 255) for i in range(256-len(palette))])
self.potentialsImage = QImage(imagebmp, rx, ry, QImage.Format_Indexed8)
self.potentialsImage.setColorTable(palette)
self.potentialsImage.setNumColors(256)
self.pixmap_item.setPixmap(QPixmap.fromImage(self.potentialsImage))
self.pixmap_item.setPos(self.graph_transform().map(self.rect.bottomLeft()))
示例3: setupScene
# 需要导入模块: from AnyQt.QtGui import QPixmap [as 别名]
# 或者: from AnyQt.QtGui.QPixmap import fromImage [as 别名]
def setupScene(self):
self.error()
if self.data:
attr = self.stringAttrs[self.imageAttr]
titleAttr = self.allAttrs[self.titleAttr]
instances = [inst for inst in self.data
if numpy.isfinite(inst[attr])]
assert self.thumbnailView.count() == 0
size = QSizeF(self.imageSize, self.imageSize)
for i, inst in enumerate(instances):
url = self.urlFromValue(inst[attr])
title = str(inst[titleAttr])
thumbnail = GraphicsThumbnailWidget(QPixmap(), title=title)
thumbnail.setThumbnailSize(size)
thumbnail.setToolTip(url.toString())
thumbnail.instance = inst
self.thumbnailView.addThumbnail(thumbnail)
if url.isValid() and url.isLocalFile():
reader = QImageReader(url.toLocalFile())
image = reader.read()
if image.isNull():
error = reader.errorString()
thumbnail.setToolTip(
thumbnail.toolTip() + "\n" + error)
self._errcount += 1
else:
pixmap = QPixmap.fromImage(image)
thumbnail.setPixmap(pixmap)
self._successcount += 1
future = Future()
future.set_result(image)
future._reply = None
elif url.isValid():
future = self.loader.get(url)
@future.add_done_callback
def set_pixmap(future, thumb=thumbnail):
if future.cancelled():
return
assert future.done()
if future.exception():
# Should be some generic error image.
pixmap = QPixmap()
thumb.setToolTip(thumb.toolTip() + "\n" +
str(future.exception()))
else:
pixmap = QPixmap.fromImage(future.result())
thumb.setPixmap(pixmap)
self._noteCompleted(future)
else:
future = None
self.items.append(_ImageItem(i, thumbnail, url, future))
if any(it.future is not None and not it.future.done()
for it in self.items):
self.info.setText("Retrieving...\n")
else:
self._updateStatus()
示例4: setStamp
# 需要导入模块: from AnyQt.QtGui import QPixmap [as 别名]
# 或者: from AnyQt.QtGui.QPixmap import fromImage [as 别名]
def setStamp(self, stamp):
self.stamp = stamp
self.setPixmap(QPixmap.fromImage(ImageQt.ImageQt(im_numbers[stamp]), flags=Qt.AutoColor))
示例5: __init__
# 需要导入模块: from AnyQt.QtGui import QPixmap [as 别名]
# 或者: from AnyQt.QtGui.QPixmap import fromImage [as 别名]
def __init__(self, parent=None, *, mime=None, image=None):
QDialog.__init__(self, parent)
self.setupUi(self)
self._backend = None
self._backend_controls = {}
self._label_anonymous = self.tr('Anonymous')
self._label_select_login = self.tr('Select Login')
self._available_backends = []
data = None
file_name = None
if image:
self._share_type = Bi.Image
data = image
elif mime:
if mime.hasImage():
self._share_type = Bi.Image
data = mime.imageData()
elif mime.hasUrls():
urls = mime.urls()
if len(urls) == 1:
file_path = os.path.realpath(urls[0].toLocalFile())
if not os.path.isfile(file_path):
raise ValueError(self.tr('Directories can not be shared'))
file_size = os.path.getsize(file_path)
file_name = os.path.basename(file_path)
if file_size > const.BIG_FILE_WARNING_SIZE:
file_name = os.path.basename(file_path)
nice_size = format_size(file_size)
result = QMessageBox.warning(self, self.tr('Warning'),
self.tr('File "{file_name}" {nice_size}.\n'
'Are you sure you want to continue?').format(**locals()),
QMessageBox.Yes | QMessageBox.Abort)
if result == QMessageBox.Abort:
QTimer.singleShot(0, self.reject)
return
if file_has_extension(file_path, ('png', 'jpg', 'jpeg', 'bmp', 'gif')):
image = QPixmap(file_path)
else:
image = None
if not image or image.isNull():
data = read_text_from_file(file_path)
if data:
self._share_type = Bi.Text
else:
self._share_type = Bi.File
data = file_path
else:
self._share_type = Bi.Image
data = image
else:
raise ValueError(self.tr('Can not share more than one file'))
elif mime.hasText():
self._share_type = Bi.Text
data = mime.text()
else:
raise RuntimeError()
if not data:
raise ValueError(self.tr('There is no content in your clipboard.\nCopy something in order to share it.'))
if self._share_type == Bi.Image:
if not file_name:
file_name = '{}-{}.png'.format('screenshot' if image else 'image', int(time()))
if data.width() > self.image_preview.width() or data.height() > self.image_preview.height():
preview = data.scaled(self.image_preview.size(), Qt.KeepAspectRatio)
else:
preview = data
if isinstance(preview, QImage):
preview = QPixmap.fromImage(preview)
self.image_preview.setPixmap(preview)
self.preview_stack.setCurrentIndex(0)
buf = QBuffer()
data.save(buf, 'png', 100)
data = buf.data().data()
elif self._share_type == Bi.Text:
if not file_name:
file_name = 'file-{}.txt'.format(int(time()))
self.text_preview.setPlainText(dedent_text_and_truncate(data, 128))
self.preview_stack.setCurrentIndex(1)
elif self._share_type == Bi.File:
if not file_name:
file_name = 'file-{}.bin'.format(int(time()))
self.text_preview.setPlainText(self.tr('No preview available'))
self.preview_stack.setCurrentIndex(1)
self._file_name = file_name
self._data = data
self.populate_backends()
self.share.pressed.connect(self.share_item)
self.add_login.pressed.connect(self.on_add_login)
self.logout.pressed.connect(self.logout_selected)
self.login_list.currentIndexChanged.connect(self.select_login)
min_height = self.backend_selector.minimumSizeHint().height()
#.........这里部分代码省略.........
示例6: setup_scene
# 需要导入模块: from AnyQt.QtGui import QPixmap [as 别名]
# 或者: from AnyQt.QtGui.QPixmap import fromImage [as 别名]
def setup_scene(self, process_grid=True):
self.error()
if self.data:
attr = self.stringAttrs[self.imageAttr]
assert self.thumbnailView.count() == 0
size = QSizeF(self.imageSize, self.imageSize)
if process_grid and self.image_grid:
self.process()
self.columns = self.image_grid.size_x
self.rows = self.image_grid.size_y
self.thumbnailView.setFixedColumnCount(self.columns)
self.thumbnailView.setFixedRowCount(self.rows)
for i, inst in enumerate(self.image_grid.image_list):
thumbnail = GraphicsThumbnailWidget(QPixmap(), crop=self.cell_fit == 1)
thumbnail.setThumbnailSize(size)
thumbnail.instance = inst
self.thumbnailView.addThumbnail(thumbnail)
if not np.isfinite(inst[attr]) or inst[attr] == "?": # skip missing
future, url = None, None
else:
url = self.url_from_value(inst[attr])
thumbnail.setToolTip(url.toString())
self.nonempty.append(i)
if url.isValid() and url.isLocalFile():
reader = QImageReader(url.toLocalFile())
image = reader.read()
if image.isNull():
error = reader.errorString()
thumbnail.setToolTip(
thumbnail.toolTip() + "\n" + error)
self._errcount += 1
else:
pixmap = QPixmap.fromImage(image)
thumbnail.setPixmap(pixmap)
self._successcount += 1
future = Future()
future.set_result(image)
future._reply = None
elif url.isValid():
future = self.loader.get(url)
@future.add_done_callback
def set_pixmap(future, thumb=thumbnail):
if future.cancelled():
return
assert future.done()
if future.exception():
# Should be some generic error image.
pixmap = QPixmap()
thumb.setToolTip(thumb.toolTip() + "\n" +
str(future.exception()))
else:
pixmap = QPixmap.fromImage(future.result())
thumb.setPixmap(pixmap)
self._note_completed(future)
else:
future = None
self.items.append(_ImageItem(i, thumbnail, url, future))
if any(not it.future.done() if it.future else False for it in self.items):
self.info.setText("Retrieving...\n")
else:
self._update_status()
self.apply_subset()
self.update_selection()