2015-12-15 29 views
1

我期待使用QtCreator和Python構建一個mipmapping程序。到目前爲止,我的應用程序是這樣的:Python中的Mipmapping?

Design

在這裏您可以上傳圖片到該程序,它會告訴你在左側的標籤盒的原始圖像。當您按下創建mipmap時,它應該顯示在正確的標籤框中的mipmap。

當你上傳一張照片,它看起來像這樣: Program

接下來的部分是我在哪裏卡住了。是否有一個在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的創建的貼圖?

任何幫助表示讚賞。

回答

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') 
+0

但是那麼連接圖像呢? –

+0

你連接了什麼?一個mipmap只是一個較小的分辨率的圖像,對不對? –

+0

這是一組較小的分辨率。 –