本文整理汇总了Python中PyQt4.Qt.QImage.scaledToHeight方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.scaledToHeight方法的具体用法?Python QImage.scaledToHeight怎么用?Python QImage.scaledToHeight使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QImage
的用法示例。
在下文中一共展示了QImage.scaledToHeight方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _populate_covers
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import scaledToHeight [as 别名]
def _populate_covers(self):
'''
Display calibre cover for both unless mismatch
'''
def _fetch_marvin_cover(border_width=0):
'''
Retrieve LargeCoverJpg from cache
'''
#self._log_location('border_width: {0}'.format(border_width))
con = sqlite3.connect(self.marvin_db_path)
with con:
con.row_factory = sqlite3.Row
# Fetch Hash from mainDb
cover_cur = con.cursor()
cover_cur.execute('''SELECT
Hash
FROM Books
WHERE ID = '{0}'
'''.format(self.book_id))
row = cover_cur.fetchone()
book_hash = row[b'Hash']
large_covers_subpath = self.connected_device._cover_subpath(size="large")
cover_path = '/'.join([large_covers_subpath, '%s.jpg' % book_hash])
stats = self.parent.ios.exists(cover_path)
if stats:
self._log("fetching large cover from cache")
#self._log("cover size: {:,} bytes".format(int(stats['st_size'])))
cover_bytes = self.parent.ios.read(cover_path, mode='rb')
m_image = QImage()
m_image.loadFromData(cover_bytes)
if border_width:
# Construct a QPixmap with oversized yellow background
m_image = m_image.scaledToHeight(
self.COVER_ICON_SIZE - border_width * 2,
Qt.SmoothTransformation)
self.m_pixmap = QPixmap(
QSize(m_image.width() + border_width * 2,
m_image.height() + border_width * 2))
m_painter = QPainter(self.m_pixmap)
m_painter.setRenderHints(m_painter.Antialiasing)
m_painter.fillRect(self.m_pixmap.rect(), self.MISMATCH_COLOR)
m_painter.drawImage(border_width,
border_width,
m_image)
else:
m_image = m_image.scaledToHeight(
self.COVER_ICON_SIZE,
Qt.SmoothTransformation)
self.m_pixmap = QPixmap(
QSize(m_image.width(),
m_image.height()))
m_painter = QPainter(self.m_pixmap)
m_painter.setRenderHints(m_painter.Antialiasing)
m_painter.drawImage(0, 0, m_image)
self.marvin_cover.setPixmap(self.m_pixmap)
else:
# No cover available, use generic
self._log("No cached cover, using generic")
pixmap = QPixmap()
pixmap.load(I('book.png'))
pixmap = pixmap.scaled(self.COVER_ICON_SIZE,
self.COVER_ICON_SIZE,
aspectRatioMode=Qt.KeepAspectRatio,
transformMode=Qt.SmoothTransformation)
self.marvin_cover.setPixmap(pixmap)
self.calibre_cover.setMaximumSize(QSize(self.COVER_ICON_SIZE, self.COVER_ICON_SIZE))
self.calibre_cover.setText('')
self.calibre_cover.setScaledContents(False)
self.marvin_cover.setMaximumSize(QSize(self.COVER_ICON_SIZE, self.COVER_ICON_SIZE))
self.marvin_cover.setText('')
self.marvin_cover.setScaledContents(False)
if self.cid:
db = self.opts.gui.current_db
if 'cover_hash' not in self.mismatches:
mi = db.get_metadata(self.cid, index_is_id=True, get_cover=True, cover_as_data=True)
c_image = QImage()
if mi.has_cover:
c_image.loadFromData(mi.cover_data[1])
c_image = c_image.scaledToHeight(self.COVER_ICON_SIZE,
Qt.SmoothTransformation)
self.c_pixmap = QPixmap(QSize(c_image.width(),
c_image.height()))
c_painter = QPainter(self.c_pixmap)
c_painter.setRenderHints(c_painter.Antialiasing)
c_painter.drawImage(0, 0, c_image)
else:
#.........这里部分代码省略.........
示例2: _fetch_marvin_cover
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import scaledToHeight [as 别名]
def _fetch_marvin_cover(border_width=0):
'''
Retrieve LargeCoverJpg from cache
'''
#self._log_location('border_width: {0}'.format(border_width))
con = sqlite3.connect(self.marvin_db_path)
with con:
con.row_factory = sqlite3.Row
# Fetch Hash from mainDb
cover_cur = con.cursor()
cover_cur.execute('''SELECT
Hash
FROM Books
WHERE ID = '{0}'
'''.format(self.book_id))
row = cover_cur.fetchone()
book_hash = row[b'Hash']
large_covers_subpath = self.connected_device._cover_subpath(size="large")
cover_path = '/'.join([large_covers_subpath, '%s.jpg' % book_hash])
stats = self.parent.ios.exists(cover_path)
if stats:
self._log("fetching large cover from cache")
#self._log("cover size: {:,} bytes".format(int(stats['st_size'])))
cover_bytes = self.parent.ios.read(cover_path, mode='rb')
m_image = QImage()
m_image.loadFromData(cover_bytes)
if border_width:
# Construct a QPixmap with oversized yellow background
m_image = m_image.scaledToHeight(
self.COVER_ICON_SIZE - border_width * 2,
Qt.SmoothTransformation)
self.m_pixmap = QPixmap(
QSize(m_image.width() + border_width * 2,
m_image.height() + border_width * 2))
m_painter = QPainter(self.m_pixmap)
m_painter.setRenderHints(m_painter.Antialiasing)
m_painter.fillRect(self.m_pixmap.rect(), self.MISMATCH_COLOR)
m_painter.drawImage(border_width,
border_width,
m_image)
else:
m_image = m_image.scaledToHeight(
self.COVER_ICON_SIZE,
Qt.SmoothTransformation)
self.m_pixmap = QPixmap(
QSize(m_image.width(),
m_image.height()))
m_painter = QPainter(self.m_pixmap)
m_painter.setRenderHints(m_painter.Antialiasing)
m_painter.drawImage(0, 0, m_image)
self.marvin_cover.setPixmap(self.m_pixmap)
else:
# No cover available, use generic
self._log("No cached cover, using generic")
pixmap = QPixmap()
pixmap.load(I('book.png'))
pixmap = pixmap.scaled(self.COVER_ICON_SIZE,
self.COVER_ICON_SIZE,
aspectRatioMode=Qt.KeepAspectRatio,
transformMode=Qt.SmoothTransformation)
self.marvin_cover.setPixmap(pixmap)
示例3: drawOverlay
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import scaledToHeight [as 别名]
def drawOverlay(self, image, entry):
#establish painter
painter = QPainter()
#set adjustment factor
corner_fac = 0.037
category_fac = 0.27
text_fac = 0.03
#load images
category = QImage("res/" + str(entry[0]) + ".png")
upperLeft = QImage("res/upperLeft.png")
upperRight = QImage("res/upperRight.png")
lowerLeft = QImage("res/lowerLeft.png")
lowerRight = QImage("res/lowerRight.png")
#adjust overlays to image size
category = category.scaledToHeight(category_fac*image.height(), Qt.SmoothTransformation)
upperLeft = upperLeft.scaledToHeight(corner_fac*image.height(), Qt.SmoothTransformation)
upperRight = upperRight.scaledToHeight(corner_fac*image.height(), Qt.SmoothTransformation)
lowerLeft = lowerLeft.scaledToHeight(corner_fac*image.height(), Qt.SmoothTransformation)
lowerRight = lowerRight.scaledToHeight(corner_fac*image.height(), Qt.SmoothTransformation)
self.voivoifont.setPixelSize(text_fac*image.height())
# create size calculator for font
size_calculator = QFontMetrics(self.voivoifont)
text_width = size_calculator.boundingRect(entry[3]).width()
text_height = size_calculator.height()
#define text-boundary
margin_hor = 0.01*image.width()
max_text_bound = QRect(margin_hor,image.height()-image.height()/3, image.width()-image.width()/3, image.height()/3)
#format text for display
#text_elided = size_calculator.elidedText(entry[3].upper(), Qt.ElideRight, max_text_bound.width(), Qt.TextWordWrap)
text_upper = entry[3].upper()
text_bounds = size_calculator.boundingRect(max_text_bound, Qt.TextWordWrap, text_upper)
text_width = text_bounds.width()
text_height = text_bounds.height()
#calculate positions
margin_ver = 0.018*image.height()
#margin_hor = 0.01*image.width()
lower_bound = image.height()-margin_ver
upper_bound = lower_bound-lowerRight.height()-text_height-upperLeft.height()
#begin painting on image
painter.begin(image)
#first paint category
painter.drawImage(image.width()-category.width()-margin_hor, margin_ver, category)
# now background rectangle and corners + comment
if len(text_upper) > 0:
painter.fillRect(margin_hor, upper_bound , lowerLeft.width()+text_width+lowerRight.width(), lowerLeft.height()+text_height+upperLeft.height(), QColor(qRgb(255,255,255)))
painter.drawImage(margin_hor, lower_bound-lowerLeft.height(), lowerLeft)
painter.drawImage(margin_hor, upper_bound, upperLeft)
painter.drawImage(margin_hor+lowerLeft.width()+text_width, upper_bound, upperRight)
painter.drawImage(margin_hor+lowerLeft.width()+text_width,lower_bound-lowerRight.height(), lowerRight)
# write text to prepared rectangle
painter.setPen(QColor(qRgb(17,195,159)))
painter.setFont(self.voivoifont)
#print(text_upper)
painter.drawText(margin_hor+lowerLeft.width(),image.height()-lowerRight.height()-margin_ver-text_height, text_width, text_height, Qt.TextWordWrap, text_upper)
painter.end()