当前位置: 首页>>代码示例>>Python>>正文


Python QImage.scaledToHeight方法代码示例

本文整理汇总了Python中PySide.QtGui.QImage.scaledToHeight方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.scaledToHeight方法的具体用法?Python QImage.scaledToHeight怎么用?Python QImage.scaledToHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtGui.QImage的用法示例。


在下文中一共展示了QImage.scaledToHeight方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sendLocation

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaledToHeight [as 别名]
	def sendLocation(self, jid, latitude, longitude, rotate):
		latitude = latitude[:10]
		longitude = longitude[:10]

		self._d("Capturing preview...")
		QPixmap.grabWindow(QApplication.desktop().winId()).save(WAConstants.CACHE_PATH+"/tempimg.png", "PNG")
		img = QImage(WAConstants.CACHE_PATH+"/tempimg.png")

		if rotate == "true":
			rot = QTransform()
			rot = rot.rotate(90)
			img = img.transformed(rot)

		if img.height() > img.width():
			result = img.scaledToWidth(320,Qt.SmoothTransformation);
			result = result.copy(result.width()/2-50,result.height()/2-50,100,100);
		elif img.height() < img.width():
			result = img.scaledToHeight(320,Qt.SmoothTransformation);
			result = result.copy(result.width()/2-50,result.height()/2-50,100,100);
		#result = img.scaled(96, 96, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation);

		result.save( WAConstants.CACHE_PATH+"/tempimg2.jpg", "JPG" );

		f = open(WAConstants.CACHE_PATH+"/tempimg2.jpg", 'r')
		stream = base64.b64encode(f.read())
		f.close()


		os.remove(WAConstants.CACHE_PATH+"/tempimg.png")
		os.remove(WAConstants.CACHE_PATH+"/tempimg2.jpg")

		fmsg = WAXMPP.message_store.createMessage(jid);
		
		mediaItem = WAXMPP.message_store.store.Media.create()
		mediaItem.mediatype_id = WAConstants.MEDIA_TYPE_LOCATION
		mediaItem.remote_url = None
		mediaItem.preview = stream
		mediaItem.local_path ="%s,%s"%(latitude,longitude)
		mediaItem.transfer_status = 2

		fmsg.content = QtCore.QCoreApplication.translate("WAEventHandler", "Location")
		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)
		
		
		resultId = self.interfaceHandler.call("message_locationSend", (jid, latitude, longitude, stream))
		k = Key(jid, True, resultId)
		fmsg.key = k.toString()
		fmsg.save()
开发者ID:timofonic,项目名称:wazapp,代码行数:57,代码来源:waxmpp.py

示例2: sendMediaVideoFile

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaledToHeight [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)
开发者ID:timofonic,项目名称:wazapp,代码行数:47,代码来源:waxmpp.py

示例3: _getPictureForSending

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaledToHeight [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"
开发者ID:timofonic,项目名称:wazapp,代码行数:45,代码来源:waxmpp.py

示例4: sendMediaImageFile

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaledToHeight [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)
开发者ID:timofonic,项目名称:wazapp,代码行数:41,代码来源:waxmpp.py

示例5: push

# 需要导入模块: from PySide.QtGui import QImage [as 别名]
# 或者: from PySide.QtGui.QImage import scaledToHeight [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)
#.........这里部分代码省略.........
开发者ID:adriancdperu,项目名称:wazapp,代码行数:103,代码来源:wamediahandler.py


注:本文中的PySide.QtGui.QImage.scaledToHeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。