zoukankan      html  css  js  c++  java
  • 用qt代码怎样编写图片保存格式[qt4.6]

    用qt代码怎样编写图片保存格式

    qt提供了多个保存图片的接口,比较常用的接口如下
    bool QPixmap::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const
    参数说明:
    fileName 文件的路径
    可选参数:format 图片的格式(qt目前支持的格式见下表),如果未设置该值
    则根据文件路径的后缀名来判断图片的存储格式。
    可选参数:quality 图片的质量(可设置成0-100之内的值,数值越大说明保存的质量越好),如果未设置该值,则按照默认的设置来保存图片。
    表一:qt 4.6.3支持的文件格式
    格式 描述
    BMP Windows Bitmap
    JPG Joint Photographic Experts Group
    JPEG Joint Photographic Experts Group
    PNG Portable Network Graphics
    PPM Portable Pixmap
    TIFF Tagged Image File Format
    XBM X11 Bitmap
    XPM X11 Pixmap

    bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const
    参数说明同上;
    这里举个使用QPixmap保存图片的例子:

    QPixmap pixmap;
    if ( pixmap.load( "D://images//source.png" ) )
    {
    	if ( pixmap.save("distance.jpg") )
    	{
    		//save image successful
    	}
    	else
    	{
    		//save image failure;
    	}
    }
    else
    {
    	//load image failure
    }
    

     注:如果需要对图片的保存参数进行更多的设置,可以使用QImageWriter提供的接口来实现

    QT4.6中将QImage保存为JPG格式
        貌似很容易,因为看QImage的save函数说明就可以做这种事情。
        但是实际运行保存却失败。搜索之。
        发现应该要找个疙瘩放这两句话:
    #include <QtPlugin>
    Q_IMPORT_PLUGIN(qjpeg)
        之后将 QT目录/plugins/imageformats/qjpegd.lib(Debug)或者 QT目录/plugins/imageformats/qjpeg.lib(Release)也link进来就ok了。

     #QT5.2貌似没这个问题。。。。

  • 相关阅读:
    胖虎都看得懂的CSS入门
    Python-ORM之sqlalchemy的简单使用
    类似fabric主机管理demo
    Redis 数据库学习
    sublime 3插件安装记录
    斐波那契数列—java实现
    mysql基础操作记录
    [转]修改github已提交的用户名和邮箱
    python nose的html报告优化
    python report中文显示乱码
  • 原文地址:https://www.cnblogs.com/mmix2009/p/3585793.html
Copyright © 2011-2022 走看看