• 7993阅读
  • 2回复

Qt4里面的QPixmap::scaled()和QImage::scaled()怎么不起作用呢? [复制链接]

上一主题 下一主题
离线anthonymo200
 
只看楼主 正序阅读 楼主  发表于: 2010-11-25
— 本帖被 XChinux 执行加亮操作(2010-11-27) —
QT4里面, 我想对图像进行放大。 用了如下代码:
a. 使用QPixmap的方式: 
    QPalette pal;
[pre] QString filename=":/photos/1.jpg";[/pre][pre] QPixmap pixmap(filename);[pre] pixmap.scaled(800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation);[/pre][pre] pal.setBrush(QPalette::Window, QBrush(pixmap));[pre] setPalette(pal);[/pre][pre][/pre][pre]b. 使用QImage的方式: [/pre][pre]  QPalette pal;[pre] QString filename=":/photos/1.jpg";[/pre][pre] QImage image(filename);[pre] image.scaled(800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation);[/pre][pre] pal.setBrush(QPalette::Window, QBrush(image));[pre] setPalette(pal);[/pre][pre][/pre][pre]c. 使用QPixmap 与 QImage的方式: [/pre][pre]    QPalette pal;[pre] QString filename=":/photos/1.jpg";[/pre][pre] QPixmap pixmap(filename);[/pre][pre] pixmap.scaled(800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation);[/pre][pre] QImage image = pixmap.toImage();[/pre][pre] image.scaled(800,480,Qt::IgnoreAspectRatio, Qt::FastTransformation);[/pre][pre] pixmap.convertFromImage(image, Qt::AutoColor);[/pre][pre] pal.setBrush(QPalette::Window, QBrush(image));[/pre][pre] setPalette(pal);[/pre][pre]以上3种方式都不能进行放大。 [/pre][/pre][/pre][/pre][/pre][pre][/pre][pre]我在QT3的程序里面是可以实现放大的, 代码如下:[/pre][pre]QString filename = "images/bgpic.jpg";[/pre][pre]QPixmap pixmap(filename);
QImage image = pixmap.convertToImage();
image = image.scale(640,480, QImage::ScaleFree);
pixmap.convertFromImage(image, QPixmap::Auto);
[/pre][pre][/pre][pre]请高手说说在Qt4里面使用QPalette显示图片的方式如何进行放大处理。[/pre]
[/pre]
[/pre]
离线happyday23

只看该作者 2楼 发表于: 2010-11-30
看了一下你的QT4代码, 我已经知道问题在哪里了, 再看了一下你的qt3代码, 我发现答案已经在你的Qt3代码里面了!~

就是scale是不对当前调用对象起作用的, 起了变化的是返回值!~
离线anthonymo200
只看该作者 1楼 发表于: 2010-11-25
更正一下, 是小尺寸的图片变换成大图片的时候不起作用,
例如 160x120 的图片变换成640x480的图片。
快速回复
限100 字节
 
上一个 下一个