本文整理匯總了Python中PyQt4.QtGui.QImageReader.imageFormat方法的典型用法代碼示例。如果您正苦於以下問題:Python QImageReader.imageFormat方法的具體用法?Python QImageReader.imageFormat怎麽用?Python QImageReader.imageFormat使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt4.QtGui.QImageReader
的用法示例。
在下文中一共展示了QImageReader.imageFormat方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: saveTiles
# 需要導入模塊: from PyQt4.QtGui import QImageReader [as 別名]
# 或者: from PyQt4.QtGui.QImageReader import imageFormat [as 別名]
def saveTiles(self):
if self.tiles is None:
QMessageBox.warning(None, self.plugin.pluginName, self.tr("No tiles have been downloaded."))
return
# Let the user choose the directory to save to
directory = QFileDialog.getExistingDirectory(caption=self.tr("{}: Choose directory").format(self.layerDef.title))
if not directory:
# User cancelled the directory selection
return
# Build the content of the .aux.xml file containing the projection info
projection_string = (self.crs().toWkt())
pam_string = '<PAMDataset>\n' + \
'<SRS>{}</SRS>\n'.format(projection_string) + \
'</PAMDataset>'
for tile in self.tiles.tiles.values():
# Figure out the file format extension
reader = QImageReader()
buffer = QBuffer()
buffer.setData(tile.data)
buffer.open(QIODevice.ReadOnly)
extension = str(reader.imageFormat(buffer))
# Build the file name of the image file
image_file_name = "{}-{}-{}.{}".format(tile.x, tile.y, tile.zoom, extension)
image_file_path = join(directory, image_file_name)
# Save the image file
with open(image_file_path, 'wb') as image_file:
image_file.write(tile.data)
# Save the .aux.xml
with open(image_file_path + '.aux.xml', 'w') as aux_file:
aux_file.write(pam_string)
# Save the world file containing the georeferencing information
tile_rect = self.tiles.serviceInfo.getTileRect(tile.zoom, tile.x, tile.y)
tile_size = self.tiles.TILE_SIZE
with open(image_file_path + 'w', 'w') as world_file:
world_file.writelines([
str(tile_rect.width() / tile_size) + '\n',
'0\n',
'0\n',
str(-tile_rect.height() / tile_size) + '\n',
str(tile_rect.xMinimum()) + '\n',
str(tile_rect.yMaximum()) + '\n'
])
# Done
msg = self.tr("Tiles have been saved.")
self.showMessageBar(msg, QgsMessageBar.INFO, 2)