本文整理汇总了Python中PyQt4.Qt.QImage.scaled方法的典型用法代码示例。如果您正苦于以下问题:Python QImage.scaled方法的具体用法?Python QImage.scaled怎么用?Python QImage.scaled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QImage
的用法示例。
在下文中一共展示了QImage.scaled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_cover
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import scaled [as 别名]
def render_cover(self, book_id):
if self.ignore_render_requests.is_set():
return
tcdata, timestamp = self.thumbnail_cache[book_id]
use_cache = False
if timestamp is None:
# Not in cache
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, 0)
else:
has_cover, cdata, timestamp = self.model().db.new_api.cover_or_cache(book_id, timestamp)
if has_cover and cdata is None:
# The cached cover is fresh
cdata = tcdata
use_cache = True
if has_cover:
p = QImage()
p.loadFromData(cdata, CACHE_FORMAT if cdata is tcdata else "JPEG")
if p.isNull() and cdata is tcdata:
# Invalid image in cache
self.thumbnail_cache.invalidate((book_id,))
self.update_item.emit(book_id)
return
cdata = None if p.isNull() else p
if not use_cache: # cache is stale
if cdata is not None:
width, height = p.width(), p.height()
scaled, nwidth, nheight = fit_image(
width, height, self.delegate.cover_size.width(), self.delegate.cover_size.height()
)
if scaled:
if self.ignore_render_requests.is_set():
return
p = p.scaled(nwidth, nheight, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
cdata = p
# update cache
if cdata is None:
self.thumbnail_cache.invalidate((book_id,))
else:
try:
self.thumbnail_cache.insert(book_id, timestamp, image_to_data(cdata))
except EncodeError as err:
self.thumbnail_cache.invalidate((book_id,))
prints(err)
except Exception:
import traceback
traceback.print_exc()
elif tcdata is not None:
# Cover was removed, but it exists in cache, remove from cache
self.thumbnail_cache.invalidate((book_id,))
self.delegate.cover_cache.set(book_id, cdata)
self.update_item.emit(book_id)
示例2: render_cover
# 需要导入模块: from PyQt4.Qt import QImage [as 别名]
# 或者: from PyQt4.Qt.QImage import scaled [as 别名]
def render_cover(self, book_id):
cdata = self.model().db.new_api.cover(book_id)
if self.ignore_render_requests.is_set():
return
if cdata is not None:
p = QImage()
p.loadFromData(cdata)
cdata = None
if not p.isNull():
width, height = p.width(), p.height()
scaled, nwidth, nheight = fit_image(width, height, self.delegate.cover_size.width(), self.delegate.cover_size.height())
if scaled:
if self.ignore_render_requests.is_set():
return
p = p.scaled(nwidth, nheight, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
cdata = p
self.delegate.cover_cache.set(book_id, cdata)
self.update_item.emit(book_id)