2014-03-26 76 views
5

任何人都可以幫助我調整圖像的大小,而不會使圖像像素化。 這是我的代碼。結果並不像原來quality..thanks好...Qt調整圖像的最佳質量

QImage img(name); 
QPixmap pixmap; 
pixmap = pixmap.fromImage(img.scaled(width,height,Qt::IgnoreAspectRatio,Qt::FastTransformation)); 
QFile file(folder+"/"+name); 
file.open(QIODevice::WriteOnly); 
pixmap.save(&file, "jpeg",100); 
file.close(); 
+0

你縮小或擴大的形象呢?如果你擴展圖像,你將永遠有一個「大」質量損失,因爲沒有更多的新空間信息比原始圖像。儘管如此,每一次調整都將是質量的損失。有很多算法對於這些都有不同的優點和缺點。 –

+0

您是否嘗試過使用Qt :: SmoothTransformation而不是Qt :: FastTransformation? – h2so5

回答

13

你要通過Qt::SmoothTransformation改造模式,像scaled功能:

QImage img(name); 
QPixmap pixmap; 
pixmap = pixmap.fromImage(img.scaled(width,height,Qt::IgnoreAspectRatio,Qt::SmoothTransformation)); 
QFile file(folder+"/"+name); 
file.open(QIODevice::WriteOnly); 
pixmap.save(&file, "jpeg",100); 
file.close(); 
+0

感謝兄弟。現在的質量比fasttransformation更好。 –