• 3048阅读
  • 4回复

经过转换的图片如何保存【已解决】 [复制链接]

上一主题 下一主题
离线dianfengxiao
 
只看楼主 倒序阅读 楼主  发表于: 2009-07-22
经过如下转换的图片如何保存,求救啊,代码如下

QImage* ReflectPicture :: reflect(QImage*imgSrc,const QColor& c)
{
    QRgb bgcolor=c.rgb();
    int dy;
    int h=imgSrc->height();
    dy=h/3;
    int w=imgSrc->width();
    int hs=h*2 ;
    int hofs=0;//h/3 ;

    Qt :: TransformationMode mode=Qt :: SmoothTransformation ;
    QImage img=imgSrc->scaled(w,h,Qt :: IgnoreAspectRatio,mode);

    QImage *result=new QImage(w,hs,QImage :: Format_RGB32);
    
    result->fill(bgcolor);
    
    for(int x=0;x<w;x++)
        for(int y=0;y<h;y++)
            result->setPixel(x,hofs+y,img.pixel(x,y));

    if(reflectionEffect!=NoReflection)
    {
        int ht=hs-h-hofs ;
        int hte=ht ;
        for(int x=0;x<w;x++)
            for(int y=0;y<ht;y++)
            {
                QRgb color=img.pixel(x,img.height()-y-1);
                result->setPixel(x,h+hofs+y,blendColor(color,bgcolor,128*(hte-dy)/hte));
            }
            }

    return result ;
}
[ 此帖被dianfengxiao在2009-07-23 09:49重新编辑 ]
离线shiroki

只看该作者 1楼 发表于: 2009-07-22
用QImage::save存
bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const

Saves the image to the file with the given fileName, using the given image file format and quality factor. If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.

The quality factor must be in the range 0 to 100 or -1. Specify 0 to obtain small compressed files, 100 for large uncompressed files, and -1 (the default) to use the default settings.

Returns true if the image was successfully saved; otherwise returns false.
--
shiro is White
ki is tree
http://www.cuteqt.com
论坛 http://www.cuteqt.com/bbs
博客 http://www.cuteqt.com/blog
博客镜像: http://sites.cuteqt.com/cuteqt
Linux/Qt/嵌入式讨论群 http://qun.qq.com/air/5699823
离线dianfengxiao
只看该作者 2楼 发表于: 2009-07-22
这样要出错的,程序直接跳出,
离线dianfengxiao
只看该作者 3楼 发表于: 2009-07-22
虽然存了一张图片,但是是空白的
我想是不是要经过一定的转换才可以存取成功
离线dianfengxiao
只看该作者 4楼 发表于: 2009-07-23
引用第1楼shiroki于2009-07-22 17:40发表的  :
用QImage::save存
bool QImage::save ( const QString & fileName, const char * format = 0, int quality = -1 ) const
Saves the image to the file with the given fileName, using the given image file format and quality factor. If format is 0, QImage will attempt to guess the format by looking at fileName's suffix.
.......

已经解决,是是编程时逻辑错误,导致图片未初始化,楼上正解
快速回复
限100 字节
 
上一个 下一个