我希望使用QtCreator和Python构建一个mipmapping程序。到目前为止,我的应用程序看起来像这样:
您可以将图像上传到程序,并在左侧标签框中显示原始图像。当您按下create mipmap时,它应该在右侧标签框中显示mipmap。
下一部分是我被困的地方。是否有在Python中使用的mipmapping算法?我看到这个question on StackOverflow有点帮助,但是我无法安装numpy因为它不能识别我的Python 3.4,尽管它已经安装。
所以这是我到目前为止所拥有的:
from __future__ import division
from PyQt4 import QtCore, QtGui, QtOpenGL
from PyQt4.QtGui import * #Used to import QPixmap. DO NOT REMOVE.
from PyQt4.QtCore import * #Used to import Qt.KeepAspectRation. DO NOT REMOVE.
import sys, os
import mmCreator
class MyApp(QtGui.QMainWindow, mmCreator.Ui_MainWindow):
def __init__(self, parent=None):
super(MyApp, self).__init__(parent)
self.setupUi(self)
self.btnSelect.clicked.connect(self.select_image)
self.btnConvert.clicked.connect(self.mipmap)
#self.btnDownload.clicked.connect(self.download)
def select_image(self):
self.origImage.clear()
image = QtGui.QFileDialog.getOpenFileName(self,
"Select Image",
"",
"Image File (*.jpg *.png *.gif)")
pixmap = QPixmap(image)
scaledPixmap = pixmap.scaled(self.origImage.size(), Qt.KeepAspectRatio)
self.origImage.setPixmap(scaledPixmap)
self.origImage.show()
#def mipmap():
那么,除了我可以在我的程序中实现的numpy之外,还有另一种创建mipmaps的方法吗?
感谢任何帮助。
答案 0 :(得分:1)
您可以使用QPixmap.scaled创建半宽或高图像。
# Create pixmap from source file
pixmap = QPixmap('/path/to/file')
# Create scaled versions of source file.
mipmaps = []
mipmaps.append(pixmap.scaledToWidth(pixmap.width() / 2))
mipmaps.append(pixmap.scaledToWidth(pixmap.width() / 4))
# Merge scaled images into a single image
w = sum([m.width() for m in mipmaps])
h = max([m.height() for m in mipmaps])
merged_pixmap = QPixmap(w, h)
painter = QPainter(merged_pixmap)
x = 0
for mipmap in mipmaps:
painter.drawPixmap(x, 0, mipmap)
x += mipmap.width()
# Save file.
merged_pixmap.save('/path/to/file.png', 'PNG')