QPixmap,QImage图片大小缩放linux版

来源:互联网 发布:淘宝如何更换账户开店 编辑:程序博客网 时间:2024/06/05 18:03
注意事项:

1.装载图片的地址有时候会读取不到。可以多摸索一下当前系统对应的格式。

2.scaled缩放方式选择

3.注意保存路径。下面程序保存路径是当前执行文件目录中。

PicOpera::PicOpera(QObject *parent) : QObject(parent)
{
    QPixmap pixmap;
    pixmap.load("/home/arikes/Programer/Qt/ImageOpera/aa.jpg");
    QPixmap fitpixmap=pixmap.scaled(400,560, Qt::KeepAspectRatioByExpanding);
    if(fitpixmap.save("aaa2.png"))
        qDebug("aaa2jpg success");
    else
        qDebug("failed");
}

 

PicOpera::PicOpera(QObject *parent) : QObject(parent)
{
    QImage imgpic;
    imgpic.load("/home/arikes/Programer/Qt/ImageOpera/aa.jpg");
    QImage fitimgpic=imgpic.scaled(400,560, Qt::KeepAspectRatioByExpanding);
    if(fitimgpic.save("bbb.png"))
        qDebug("bbb success");
    else
        qDebug("failed");
}

以上两种都可以实现图片的大小改变。但其实他们是有区别的,参见:

http://blog.chinaunix.net/uid-25647278-id-3025412.html

0 0
原创粉丝点击