本文整理汇总了Python中PyQt4.QtGui.QImage方法的典型用法代码示例。如果您正苦于以下问题:Python QtGui.QImage方法的具体用法?Python QtGui.QImage怎么用?Python QtGui.QImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui
的用法示例。
在下文中一共展示了QtGui.QImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insertImage
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def insertImage(self):
# Get image file name
filename = QtGui.QFileDialog.getOpenFileName(self, 'Insert image',".","Images (*.png *.xpm *.jpg *.bmp *.gif)")
if filename:
# Create image object
image = QtGui.QImage(filename)
# Error if unloadable
if image.isNull():
popup = QtGui.QMessageBox(QtGui.QMessageBox.Critical,
"Image load error",
"Could not load image file!",
QtGui.QMessageBox.Ok,
self)
popup.show()
else:
cursor = self.text.textCursor()
cursor.insertImage(image,filename)
示例2: insertImage
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def insertImage(self):
# Get image file name
filename = QtGui.QFileDialog.getOpenFileName(self, 'Insert image',".","Images (*.png *.xpm *.jpg *.bmp *.gif)")
if filename:
# Create image object
image = QtGui.QImage(filename)
# Error if unloadable
if image.isNull():
popup = QtGui.QMessageBox(QtGui.QMessageBox.Critical,
"Image load error",
"Could not load image file!",
QtGui.QMessageBox.Ok,
self)
popup.show()
else:
cursor = self.text.textCursor()
cursor.insertImage(image,filename)
示例3: open
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def open(self):
fileName = QtGui.QFileDialog.getOpenFileName(self, "Open File",
QtCore.QDir.currentPath())
if fileName:
image = QtGui.QImage(fileName)
if image.isNull():
QtGui.QMessageBox.information(self, "Image Viewer",
"Cannot load %s." % fileName)
return
self.imageLabel.setPixmap(QtGui.QPixmap.fromImage(image))
self.scaleFactor = 1.0
self.printAct.setEnabled(True)
self.fitToWindowAct.setEnabled(True)
self.updateActions()
if not self.fitToWindowAct.isChecked():
self.imageLabel.adjustSize()
示例4: setImage
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def setImage(self, image):
""" Set the scene's current image pixmap to the input QImage or QPixmap.
Raises a RuntimeError if the input image has type other than QImage or QPixmap.
:type image: QImage | QPixmap
"""
if type(image) is QPixmap:
pixmap = image
elif type(image) is QImage:
pixmap = QPixmap.fromImage(image)
else:
raise RuntimeError("ImageViewer.setImage: Argument must be a QImage or QPixmap.")
if self.hasImage():
self._pixmapHandle.setPixmap(pixmap)
else:
self._pixmapHandle = self.scene.addPixmap(pixmap)
self.setSceneRect(QRectF(pixmap.rect())) # Set scene size to image size.
self.updateViewer()
示例5: savePascalVocFormat
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def savePascalVocFormat(self, filename, shapes, imagePath, imageData,
lineColor=None, fillColor=None, databaseSrc=None):
imgFolderPath = os.path.dirname(imagePath)
imgFolderName = os.path.split(imgFolderPath)[-1]
imgFileName = os.path.basename(imagePath)
imgFileNameWithoutExt = os.path.splitext(imgFileName)[0]
# Read from file path because self.imageData might be empty if saving to
# Pascal format
image = QImage()
image.load(imagePath)
imageShape = [image.height(), image.width(), 1 if image.isGrayscale() else 3]
writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt,\
imageShape, localImgPath=imagePath)
bSave = False
for shape in shapes:
points = shape['points']
label = shape['label']
bndbox = LabelFile.convertPoints2BndBox(points)
writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label)
bSave = True
if bSave:
writer.save(targetFile = filename)
return
示例6: loadImage
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def loadImage(self):
success = False
message = self.defaultStatusbar
if self.images:
filename = self.images[self.idx]
filename = os.path.normpath( filename )
if not self.image.isNull() and filename == self.config.currentFile:
success = True
else:
self.image = QtGui.QImage(filename)
if self.image.isNull():
message = "Failed to read image: {0}".format( filename )
else:
message = "Read image: {0}".format( filename )
self.config.currentFile = filename
success = True
# Update toolbar actions that need an image
for act in self.actImage:
act.setEnabled(success)
for act in self.actImageNotFirst:
act.setEnabled(success and self.idx > 0)
for act in self.actImageNotLast:
act.setEnabled(success and self.idx < len(self.images)-1)
self.statusBar().showMessage(message)
# Load the labels from file
# Only loads if they exist
# Otherwise the filename is stored and that's it
示例7: loadImage
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def loadImage(self):
success = False
message = self.defaultStatusbar
if self.images:
filename = self.images[self.idx]
filename = os.path.normpath( filename )
if not self.image.isNull() and filename == self.currentFile:
success = True
else:
self.image = QtGui.QImage(filename)
if self.image.isNull():
message = "Failed to read image: {0}".format( filename )
else:
message = "Read image: {0}".format( filename )
self.currentFile = filename
success = True
# Update toolbar actions that need an image
for act in self.actImage:
act.setEnabled(success)
for act in self.actImageNotFirst:
act.setEnabled(success and self.idx > 0)
for act in self.actImageNotLast:
act.setEnabled(success and self.idx < len(self.images)-1)
self.statusBar().showMessage(message)
# Load the labels from file
# Only loads if they exist
# Otherwise the filename is stored and that's it
示例8: drawZoom
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def drawZoom(self,qp,overlay):
# Zoom disabled?
if not self.zoom:
return
# No image
if self.image.isNull() or not self.w or not self.h:
return
# No mouse
if not self.mousePosOrig:
return
# Abbrevation for the zoom window size
zoomSize = self.zoomSize
# Abbrevation for the mouse position
mouse = self.mousePosOrig
# The pixel that is the zoom center
pix = self.mousePosScaled
# The size of the part of the image that is drawn in the zoom window
selSize = zoomSize / ( self.zoomFactor * self.zoomFactor )
# The selection window for the image
sel = QtCore.QRectF(pix.x() -selSize/2 ,pix.y() -selSize/2 ,selSize,selSize )
# The selection window for the widget
view = QtCore.QRectF(mouse.x()-zoomSize/2,mouse.y()-zoomSize/2,zoomSize,zoomSize)
if overlay :
overlay_scaled = overlay.scaled(self.image.width(), self.image.height())
else :
overlay_scaled = QtGui.QImage( self.image.width(), self.image.height(), QtGui.QImage.Format_ARGB32_Premultiplied )
# Show the zoom image
qp.save()
qp.drawImage(view,self.image,sel)
qp.setOpacity(self.transp)
qp.drawImage(view,overlay_scaled,sel)
qp.restore()
# Draw disparities
示例9: show_image
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def show_image(self, image):
image = QtGui.QImage(image)
bg = QtGui.QPixmap.fromImage(image)
self.setPixmap(bg.scaled(
self.size(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
示例10: getTilesReply
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def getTilesReply(self):
print "getTilesReply " + str(self.getIndex)
if self.tilereply.error() != QNetworkReply.NoError:
return
self.tileQimages.append(QImage())
self.tileQimages[self.getIndex].loadFromData(self.tilereply.readAll())
self.getIndex = self.getIndex + 1
if self.getIndex < len(self.tileurls):
self.getTiles(self.getTime, self.getIndex)
else:
self.combineTiles()
self.get()
示例11: get_icon
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def get_icon(icon, size=24):
"""get svg icon from icon resources folder as a pixel map
"""
img = get_icon_path("{}.svg".format(icon))
svg_renderer = QtSvg.QSvgRenderer(img)
image = QtGui.QImage(size, size, QtGui.QImage.Format_ARGB32)
# Set the ARGB to 0 to prevent rendering artifacts
image.fill(0x00000000)
svg_renderer.render(QtGui.QPainter(image))
pixmap = QtGui.QPixmap.fromImage(image)
return pixmap
示例12: emitNextFrame
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def emitNextFrame(self):
""" capture frame and reverse RBG BGR and return opencv image """
if self.cam.query_image():
self.buffer = self.cam.get_image(self.buffer)
data = pygame.image.tostring(self.buffer, "RGBA")
image = QtGui.QImage(data, self.size[0], self.size[1], QtGui.QImage.Format_ARGB32).rgbSwapped() # This seems to make a copy, it would be good if we could just change the header?
pixmap = QtGui.QPixmap.fromImage(image)
self.sigPixmap.emit(pixmap)
示例13: image_get
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def image_get(self):
self.runLock.acquire(True)
con=card.connection(self.ipAddr, self.port, self.timeout)
while self.run:
self.runLock.release()
fileName=con.sync_new_pictures_since_start(self.folder_remote, self.folder_local)
if(len(fileName)>0):
print(fileName)
image=QtGui.QImage(fileName)
self.emit(QtCore.SIGNAL('load_image(QImage)'), image)
time.sleep(1)
pass
self.runLock.acquire(True)
self.runLock.release()
print("Exiting thread...")
示例14: __init__
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def __init__(self, *args, **kwargs):
StatusIcon.__init__(self, *args, **kwargs)
try:
import PyQt4.Qt as qt
import PyQt4.QtGui as qtgui
import PyKDE4.kdeui as kdeui
self._set_qt_types(
QAction = qtgui.QAction,
QMenu = kdeui.KMenu,
QIcon = qtgui.QIcon,
QImage = qtgui.QImage,
QPixmap = qtgui.QPixmap
)
self._status_active = kdeui.KStatusNotifierItem.Active
self._status_passive = kdeui.KStatusNotifierItem.Passive
except ImportError:
raise NotImplementedError
if b"GNOME_DESKTOP_SESSION_ID" in os.environ:
del os.environ[b"GNOME_DESKTOP_SESSION_ID"]
# Create Qt GUI application (required by the KdeUI libraries)
# We force "--style=motif" here to prevent Qt to load platform theme
# integration libraries for "Gtk+" style that cause GTK 3 to abort like this:
# Gtk-ERROR **: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
self._qt_app = qt.QApplication([sys.argv[0], "--style=motif"])
# Keep reference to KMenu object to prevent SegFault...
self._kde_menu = self._get_popupmenu()
self._tray = kdeui.KStatusNotifierItem("syncthing-gtk", None)
self._tray.setStandardActionsEnabled(False) # Prevent KDE quit item from showing
self._tray.setContextMenu(self._kde_menu)
self._tray.setCategory(kdeui.KStatusNotifierItem.ApplicationStatus)
self._tray.setTitle(self.TRAY_TITLE)
self._tray.activateRequested.connect(self._on_click)
示例15: draw_predictions
# 需要导入模块: from PyQt4 import QtGui [as 别名]
# 或者: from PyQt4.QtGui import QImage [as 别名]
def draw_predictions(file_path, predictions, class_index,
score_low, score_high):
img = QtGui.QImage(file_path)
painter = QtGui.QPainter(img)
for i, pred in enumerate(predictions):
if class_index > 0 and pred.class_index != class_index: continue
if pred.score < score_low or pred.score > score_high: continue
class_name = CLASS_NAMES[pred.class_index]
x1, y1, x2, y2 = map(int, pred.bbox)
# bbox
painter.setPen(QtGui.QPen(PRESET_COLORS[pred.class_index], 10.0))
# painter.setPen(QtGui.QPen(QtGui.QColor(0, 116, 217), 10.0))
painter.setBrush(QtGui.QBrush())
painter.drawRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1)
# label background rect
painter.setPen(QtGui.QPen(PRESET_COLORS[pred.class_index], 2.0))
painter.setBrush(QtGui.QBrush(PRESET_COLORS[pred.class_index]))
# painter.setPen(QtGui.QPen(QtGui.QColor(0, 116, 217), 2.0))
# painter.setBrush(QtGui.QBrush(QtGui.QColor(0, 116, 217)))
if class_index > 0:
painter.drawRect(x1, y1, min(x2 - x1 + 1, 100), 30)
else:
painter.drawRect(x1, y1, min(x2 - x1 + 1, 200), 30)
# label text
painter.setPen(QtGui.QPen(QtGui.QColor(255, 255, 255)))
painter.setBrush(QtGui.QBrush())
painter.setFont(QtGui.QFont('Arial', 20, QtGui.QFont.Bold))
if class_index > 0:
painter.drawText(x1 + 4, y1 + 24, '{:.2f}'.format(pred.score))
else:
painter.drawText(x1 + 4, y1 + 24,
'{} {:.2f}'.format(class_name, pred.score))
return img