2014-01-16 30 views
0

我在嘗試將圖像大小調整爲120X240。QImage :: scaleHeight轉換模式返回NULL圖像

image = image.scaledToHeight(120); 
image = image.scaledToWidth(240); 

對於具有尺寸837x630,得到錯誤的一些圖片,

QImage::scaleHeight: Image is a null image 
QImage::scaleWidth: Image is a null image 

其中具有幾乎相同的尺寸有些圖像scalling正確(837X 642) 什麼是對那些errors..Some的原因圖像正確縮放,有些不是......爲什麼?

+0

我們可以看看你是如何初始化'image'的? – Shoe

+0

QString lPath =(QString)GPathAlphabets.c_str(); lPath.append(「/」)。append(pAlphabetFilePath); QImage image(lPath); – user3167959

回答

0

您的構造函數QImage以某種方式構造了一個空圖像。你應該處理的情況下出現這種情況與QImage::isNull

if (image.isNull()) 
    // throw error 

你也應該這樣做:

image = QImage(image.scaled(240, 120)); 

代替。

+0

如果給定的高度/寬度爲零或負值,則只有當時它必須返回NULL圖像。但在我的情況下,圖像具有有效的高度和寬度.. – user3167959

+0

@ user3167959,我說的是'image'在函數調用時已經是空圖像來縮放它。 – Shoe