本文整理汇总了Python中PySide.QtGui.QImage.scaled方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.scaled方法的具体用法?Python QImage.scaled怎么用?Python QImage.scaled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QImage
的用法示例。
在下文中一共展示了QImage.scaled方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requestImage
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def requestImage(self, id, size, requestedSize):
key = (id, requestedSize)
if key in self._cache:
return self._cache[key]
cover_file, cover_url, podcast_url, podcast_title = id.split('|')
def get_filename():
return self.downloader.get_cover(cover_file, cover_url,
podcast_url, podcast_title, None, None, True)
filename = get_filename()
image = QImage()
if not image.load(filename):
if filename.startswith(cover_file):
logger.info('Deleting broken cover art: %s', filename)
util.delete_file(filename)
image.load(get_filename())
if not image.isNull():
self._cache[key] = image.scaled(requestedSize,
Qt.KeepAspectRatioByExpanding,
Qt.SmoothTransformation)
return self._cache[key]
示例2: __init__
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
class HeroShipView:
""" Represents the Graphical view of the Hero's ship """
def __init__(self, ship_model):
""" Initialize the ship view """
self.ship_model = ship_model
self.scaled_ship = None
def loadShipImage(self, width, height):
""" Load the ship image """
self.unscaled_ship = QImage("hero_ship.png")
matrix = QMatrix()
matrix = matrix.rotate(180)
self.unscaled_ship = self.unscaled_ship.transformed(matrix)
xScaledSize = width*self.ship_model.rectangle.width/100
yScaledSize = height*self.ship_model.rectangle.height/100
self.scaled_ship = self.unscaled_ship.scaled(xScaledSize, yScaledSize)
def draw(self, painter, window):
""" Draw the image """
if self.scaled_ship is None:
self.loadShipImage(window.contentsRect().width(), window.contentsRect().height())
painter.drawImage(self.ship_model.rectangle.x*window.contentsRect().width()/100, self.ship_model.rectangle.y*window.contentsRect().height()/100, self.scaled_ship)
示例3: LoadImage
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def LoadImage(imageFilename, scaledXSize=None, scaledYSize=None):
""" Loads the Image and scales it if necessary """
unscaled_image = QImage(imageFilename)
if scaledXSize is not None and scaledYSize is not None:
return unscaled_image.scaled(scaledXSize, scaledYSize)
else:
return unscaled_image
示例4: getContacts
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def getContacts(self):
contacts = self.store.Contact.fetchAll();
if len(contacts) == 0:
#print "RESYNCING";
#self.resync();
return contacts;
#O(n2) matching, need to change that
cm = self.manager
phoneContacts = cm.getContacts();
tmp = []
self.contacts = {};
if not os.path.exists("/home/user/.cache/wazapp/contacts"):
os.makedirs("/home/user/.cache/wazapp/contacts")
for wc in contacts:
for c in phoneContacts:
if wc.number == c['number']:
#@@TODO cache to enhance startup
jname = wc.jid.replace("@s.whatsapp.net","")
if not os.path.isfile("/home/user/.cache/wazapp/contacts/" + jname + ".png"):
user_img = QImage(QUrl(c['picture']).toString().replace("file://",""))
if os.path.isfile("/home/user/.cache/wazapp/contacts/" + jname + ".jpg"):
user_img = QImage("/home/user/.cache/wazapp/contacts/" + jname + ".jpg")
mask_img = QImage("/opt/waxmppplugin/bin/wazapp/UI/common/images/usermask.png")
preimg = QPixmap.fromImage(QImage(user_img.scaled(96, 96, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)));
PixmapToBeMasked = QImage(96, 96, QImage.Format_ARGB32_Premultiplied);
Mask = QPixmap.fromImage(mask_img);
Painter = QPainter(PixmapToBeMasked);
Painter.drawPixmap(0, 0, 96, 96, preimg);
Painter.setCompositionMode(QPainter.CompositionMode_DestinationIn);
Painter.drawPixmap(0, 0, 96, 96, Mask);
Painter.end()
PixmapToBeMasked.save("/home/user/.cache/wazapp/contacts/" + jname + ".png", "PNG")
if os.path.isfile("/home/user/.cache/wazapp/contacts/" + jname + ".jpg"):
os.remove("/home/user/.cache/wazapp/contacts/" + jname + ".jpg")
c['picture'] = "/home/user/.cache/wazapp/contacts/" + jname + ".png";
wc.setRealTimeData(c['name'],c['picture']);
if wc.status is not None:
wc.status = wc.status.decode('utf-8');
#tmp.append(wc.toModel());
tmp.append(wc.getModelData());
self.contacts[wc.number] = wc;
break;
self.store.cacheContacts(self.contacts);
return sorted(tmp, key=lambda k: k['name'].upper()) ;
示例5: updateContact
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def updateContact(self,jid):
jname = jid.replace("@s.whatsapp.net","").replace("@g.us","")
user_img = QImage("/opt/waxmppplugin/bin/wazapp/UI/common/images/user.png")
user_img.save("/home/user/.cache/wazapp/contacts/" + jname + ".png", "PNG")
user_img = QImage("/home/user/.cache/wazapp/contacts/" + jname + ".jpg")
mask_img = QImage("/opt/waxmppplugin/bin/wazapp/UI/common/images/usermask.png")
preimg = QPixmap.fromImage(QImage(user_img.scaled(96, 96, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)));
PixmapToBeMasked = QImage(96, 96, QImage.Format_ARGB32_Premultiplied);
Mask = QPixmap.fromImage(mask_img);
Painter = QPainter(PixmapToBeMasked);
Painter.drawPixmap(0, 0, 96, 96, preimg);
Painter.setCompositionMode(QPainter.CompositionMode_DestinationIn);
Painter.drawPixmap(0, 0, 96, 96, Mask);
Painter.end()
PixmapToBeMasked.save("/home/user/.cache/wazapp/contacts/" + jname + ".png", "PNG")
os.remove("/home/user/.cache/wazapp/contacts/" + jname + ".jpg")
self.contactUpdated.emit(jid);
示例6: sendMediaVideoFile
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def sendMediaVideoFile(self,jid,video,image):
self._d("creating VIDEO MMS for " +jid + " - file: " + video)
fmsg = WAXMPP.message_store.createMessage(jid);
if image == "NOPREVIEW":
m = hashlib.md5()
url = QtCore.QUrl(video).toEncoded()
m.update(url)
image = WAConstants.THUMBS_PATH + "/screen/" + m.hexdigest() + ".jpeg"
else:
image = image.replace("file://","")
user_img = QImage(image)
if user_img.height() > user_img.width():
preimg = QPixmap.fromImage(QImage(user_img.scaledToWidth(64, Qt.SmoothTransformation)))
elif user_img.height() < user_img.width():
preimg = QPixmap.fromImage(QImage(user_img.scaledToHeight(64, Qt.SmoothTransformation)))
else:
preimg = QPixmap.fromImage(QImage(user_img.scaled(64, 64, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)))
preimg.save(WAConstants.CACHE_PATH+"/temp2.png", "PNG")
f = open(WAConstants.CACHE_PATH+"/temp2.png", 'r')
stream = base64.b64encode(f.read())
f.close()
mediaItem = WAXMPP.message_store.store.Media.create()
mediaItem.mediatype_id = 4
mediaItem.local_path = video.replace("file://","")
mediaItem.transfer_status = 0
mediaItem.preview = stream
try:
mediaItem.size = os.path.getsize(mediaItem.local_path)
except:
pass
fmsg.content = QtCore.QCoreApplication.translate("WAEventHandler", "Video")
fmsg.Media = mediaItem
if fmsg.Conversation.type == "group":
contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(self.conn.jid)
fmsg.setContact(contact);
fmsg.setData({"status":0,"content":fmsg.content,"type":1})
WAXMPP.message_store.pushMessage(jid,fmsg)
示例7: checkPicture
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def checkPicture(self,jname,imagepath):
if not os.path.isfile("/home/user/.cache/wazapp/contacts/" + jname + ".png"):
user_img = QImage("/opt/waxmppplugin/bin/wazapp/UI/common/images/user.png")
if imagepath is not "":
user_img = QImage(QUrl(imagepath).toString().replace("file://",""))
if os.path.isfile("/home/user/.cache/wazapp/contacts/" + jname + ".jpg"):
user_img = QImage("/home/user/.cache/wazapp/contacts/" + jname + ".jpg")
mask_img = QImage("/opt/waxmppplugin/bin/wazapp/UI/common/images/usermask.png")
preimg = QPixmap.fromImage(QImage(user_img.scaled(96, 96, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)));
PixmapToBeMasked = QImage(96, 96, QImage.Format_ARGB32_Premultiplied);
Mask = QPixmap.fromImage(mask_img);
Painter = QPainter(PixmapToBeMasked);
Painter.drawPixmap(0, 0, 96, 96, preimg);
Painter.setCompositionMode(QPainter.CompositionMode_DestinationIn);
Painter.drawPixmap(0, 0, 96, 96, Mask);
Painter.end()
PixmapToBeMasked.save("/home/user/.cache/wazapp/contacts/" + jname + ".png", "PNG")
if os.path.isfile("/home/user/.cache/wazapp/contacts/" + jname + ".jpg"):
os.remove("/home/user/.cache/wazapp/contacts/" + jname + ".jpg")
示例8: _getPictureForSending
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def _getPictureForSending(self, jid, filepath):
print "Preparing picture " + filepath + " for " + jid
image = filepath.replace("file://","")
rotation = 0
ret = {}
im = Image.open(image)
try:
info = im._getexif()
for tag, value in info.items():
decoded = TAGS.get(tag, value)
ret[decoded] = value
if ret['Orientation'] == 6:
rotation = 90
except:
rotation = 0
user_img = QImage(image)
if rotation == 90:
rot = QTransform()
rot = rot.rotate(90)
user_img = user_img.transformed(rot)
if user_img.height() > user_img.width():
preimg = user_img.scaledToWidth(480, Qt.SmoothTransformation)
preimg = preimg.copy( 0, preimg.height()/2-240, 480, 480);
elif user_img.height() < user_img.width():
preimg = user_img.scaledToHeight(480, Qt.SmoothTransformation)
preimg = preimg.copy( preimg.width()/2-240, 0, 480, 480);
else:
preimg = user_img.scaled(480, 480, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)
preimg.save(WAConstants.CACHE_PATH+"/temp.jpg", "JPG")
''''f = open(WAConstants.CACHE_PATH+"/temp.jpg", 'r')
stream = f.read()
stream = bytearray(stream)
f.close()
'''
return WAConstants.CACHE_PATH+"/temp.jpg"
示例9: __init__
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
class BackgroundView:
""" Represents the Graphical view of the Background """
def __init__(self):
""" Initialize the backgroound view """
self.scaled_background = None
def loadBackgroundImage(self, width, height):
""" Load the ship image """
xScaledSize = width
yScaledSize = height
self.unscaled_background = QImage("Space_Background_bigger.gif")
self.scaled_background = self.unscaled_background.scaled(xScaledSize, yScaledSize)
def draw(self, painter, window):
""" Draw the image """
if self.scaled_background is None:
self.loadBackgroundImage(window.contentsRect().width(), window.contentsRect().height())
painter.drawImage(0, 0, self.scaled_background)
示例10: sendMediaImageFile
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def sendMediaImageFile(self,jid,image):
image = image.replace("file://","")
user_img = QImage(image)
if user_img.height() > user_img.width():
preimg = QPixmap.fromImage(QImage(user_img.scaledToWidth(64, Qt.SmoothTransformation)))
elif user_img.height() < user_img.width():
preimg = QPixmap.fromImage(QImage(user_img.scaledToHeight(64, Qt.SmoothTransformation)))
else:
preimg = QPixmap.fromImage(QImage(user_img.scaled(64, 64, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)))
preimg.save(WAConstants.CACHE_PATH+"/temp2.png", "PNG")
f = open(WAConstants.CACHE_PATH+"/temp2.png", 'r')
stream = base64.b64encode(f.read())
f.close()
self._d("creating PICTURE MMS for " +jid + " - file: " + image)
fmsg = WAXMPP.message_store.createMessage(jid);
mediaItem = WAXMPP.message_store.store.Media.create()
mediaItem.mediatype_id = 2
mediaItem.local_path = image
mediaItem.transfer_status = 0
mediaItem.preview = stream
try:
mediaItem.size = os.path.getsize(mediaItem.local_path)
except:
pass
fmsg.content = QtCore.QCoreApplication.translate("WAEventHandler", "Image")
fmsg.Media = mediaItem
if fmsg.Conversation.type == "group":
contact = WAXMPP.message_store.store.Contact.getOrCreateContactByJid(self.conn.jid)
fmsg.setContact(contact);
fmsg.setData({"status":0,"content":fmsg.content,"type":1})
WAXMPP.message_store.pushMessage(jid,fmsg)
示例11: __init__
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
class LaserView:
""" Represents the Graphical view of a Laser ship """
def __init__(self, laser_model):
""" Initialize the ship view """
self.laser = laser_model
self.scaled_laser = None
def loadShipImage(self, width, height):
""" Load the ship image """
self.unscaled_laser = QImage("laser.png")
xScaledSize = width*self.laser.rectangle.width/100
yScaledSize = height*self.laser.rectangle.height/100
self.scaled_laser = self.unscaled_laser.scaled(xScaledSize, yScaledSize)
def draw(self, painter, window):
""" Draw the image """
if self.scaled_laser is None:
self.loadShipImage(window.contentsRect().width(), window.contentsRect().height())
painter.drawImage(self.laser.rectangle.x*window.contentsRect().width()/100, self.laser.rectangle.y*window.contentsRect().height()/100, self.scaled_laser)
示例12: ImageMediaView
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
class ImageMediaView(MediaView):
def __init__(self, media, parent):
super(ImageMediaView, self).__init__(media, parent)
self._widget = QLabel(parent)
self._widget.setGeometry(media['_geometry'])
self._img = QImage()
self.set_default_widget_prop()
@Slot()
def play(self):
self._finished = 0
path = "%s/%s" % (self._save_dir, self._options['uri'])
rect = self._widget.geometry()
self._img.load(path)
self._img = self._img.scaled(rect.width(), rect.height(),
Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
self._widget.setPixmap(QPixmap.fromImage(self._img))
self._widget.show()
self._widget.raise_()
self._play_timer.setInterval(int(float(self._duration) * 1000))
self._play_timer.start()
self.started_signal.emit()
示例13: push
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
def push(self,image):
#image = urllib.quote(image)
image = image.replace("file://","")
self.sock = socket.socket();
HOST, PORT = 'mms.whatsapp.net', 443
self.sock.connect((HOST, PORT));
ssl_sock = ssl.wrap_socket(self.sock)
filename = os.path.basename(image)
filetype = mimetypes.guess_type(filename)[0]
filesize = os.path.getsize(image)
if self.resizeImages is True and "image" in filetype and not "image/gif" in filetype:
user_img = QImage(image)
preimg = user_img
if user_img.height() > user_img.width() and user_img.width() > 600:
preimg = user_img.scaledToWidth(600, Qt.SmoothTransformation)
elif user_img.height() < user_img.width() and user_img.height() > 800:
preimg = user_img.scaledToHeight(800, Qt.SmoothTransformation)
elif user_img.height() == user_img.width() and user_img.height() > 600:
preimg = user_img.scaled(600, 600, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation)
preimg.save(WAConstants.CACHE_PATH+"/" + os.path.basename(image))
image = WAConstants.CACHE_PATH+"/" + os.path.basename(image)
filename = os.path.basename(image)
filetype = mimetypes.guess_type(filename)[0]
filesize = os.path.getsize(image)
print "Uploading " + image + " - type: " + filetype + " - resize:" + str(self.resizeImages);
m = hashlib.md5()
m.update(filename)
crypto = m.hexdigest() + os.path.splitext(filename)[1]
boundary = "-------" + m.hexdigest() #"zzXXzzYYzzXXzzQQ"
contentLength = 0
hBAOS = bytearray()
hBAOS += "--" + boundary + "\r\n"
hBAOS += "Content-Disposition: form-data; name=\"to\"\r\n\r\n"
hBAOS += self.jid + "\r\n"
hBAOS += "--" + boundary + "\r\n"
hBAOS += "Content-Disposition: form-data; name=\"from\"\r\n\r\n"
hBAOS += self.account.replace("@whatsapp.net","").encode() + "\r\n"
hBAOS += "--" + boundary + "\r\n"
hBAOS += "Content-Disposition: form-data; name=\"file\"; filename=\"" + crypto.encode() + "\"\r\n"
hBAOS += "Content-Type: " + filetype + "\r\n\r\n"
fBAOS = bytearray()
fBAOS += "\r\n--" + boundary + "--\r\n"
contentLength += len(hBAOS)
contentLength += len(fBAOS)
contentLength += filesize
userAgent = "WhatsApp/2.8.4 S60Version/5.2 Device/C7-00"
POST = bytearray()
POST += "POST https://mms.whatsapp.net/client/iphone/upload.php HTTP/1.1\r\n"
POST += "Content-Type: multipart/form-data; boundary=" + boundary + "\r\n"
POST += "Host: mms.whatsapp.net\r\n"
POST += "User-Agent: WhatsApp/2.8.14 S60Version/5.3 Device/C7-00\r\n"
POST += "Content-Length: " + str(contentLength) + "\r\n\r\n"
print "sending REQUEST "
print hBAOS
ssl_sock.write(str(POST))
ssl_sock.write(str(hBAOS))
totalsent = 0
buf = 1024
f = open(image, 'r')
stream = f.read()
f.close()
status = 0
lastEmit = 0
while totalsent < int(filesize):
#print "sending " + str(totalsent) + " to " + str(totalsent+buf) + " - real: " + str(len(stream[:buf]))
ssl_sock.write(str(stream[:buf]))
status = totalsent * 100 / filesize
if lastEmit!=status and status!=100 and filesize>12288:
self.progressUpdated.emit(status)
lastEmit = status
stream = stream[buf:]
totalsent = totalsent + buf
ssl_sock.write(str(fBAOS))
if self.resizeImages is True and "image" in filetype:
os.remove(WAConstants.CACHE_PATH+"/" + os.path.basename(image))
sleep(1)
print "Done!"
print "Reading response..."
data = ssl_sock.recv(8192)
data += ssl_sock.recv(8192)
#.........这里部分代码省略.........
示例14: __init__
# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaled [as 别名]
class UpngGui:
def __init__(self):
self.ui = None
self.image = None
def main(self, argv=None):
if argv is None:
argv = sys.argv
self.app = QApplication(argv)
loader = QUiLoader()
self.ui = loader.load('./upng.ui')
self.ui.openButton.clicked.connect(self.openImage)
self.ui.resizeButton.clicked.connect(self.resizeImage)
self.ui.saveButton.clicked.connect(self.saveImage)
self.ui.show()
return self.app.exec_()
def openImage(self):
fileName = QFileDialog.getOpenFileName(self.ui,
tr("Open Image"), "./",
tr("Image Files (*.png *.jpg *.bmp *.ppm)"))
if fileName:
fileName = fileName[0]
self.image = QImage()
self.image.load(fileName)
w = self.image.width()
h = self.image.height()
self.ui.spinBoxWidth.setValue(w)
self.ui.spinBoxHeight.setValue(h)
self.resizeImage()
def resizeImage(self):
if not self.image:
self.ui.scrollArea.takeWidget()
return
w = self.ui.spinBoxWidth.value()
h = self.ui.spinBoxHeight.value()
img = self.image.scaled(w,h)
pix = QPixmap.fromImage(img)
lbl = QLabel()
lbl.setPixmap(pix)
self.ui.scrollArea.takeWidget()
self.ui.scrollArea.setWidget(lbl)
def saveImage(self):
if not self.image:
return
w = self.ui.spinBoxWidth.value()
h = self.ui.spinBoxHeight.value()
img = self.image.scaled(w,h).convertToFormat(QImage.Format_ARGB32)
fileName = QFileDialog.getSaveFileName(self.ui,
tr("Save Simple Png Image"), "./",
tr("Image Files (*.png *.ppm)"))
if fileName:
fileName = fileName[0]
self.app.setOverrideCursor(QCursor(Qt.WaitCursor))
self.ui.setEnabled(False)
if fileName.endswith('ppm'):
writePpm(fileName, img)
if fileName.endswith('png'):
writeSPangImage(fileName, img, self.app)
else:
writeSPangImage(fileName + ".png", img, self.app)
self.ui.setEnabled(True)
self.app.restoreOverrideCursor()