免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2636 | 回复: 1
打印 上一主题 下一主题

ImageMagick转换TIF文件发生Magick::WarningCoder警告 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-11-05 14:33 |只看该作者 |倒序浏览
在使用ImageMagick做TIFF文件转换时出现如下警告:
Ping Warning:ImageMagick: 001.TIF: Line length mismatch at line 0 of strip 0 (got 4410, expected 2704). `Fax4Decode'
Read Warning:ImageMagick: 001.TIF: Line length mismatch at line 0 of strip 0 (got 4410, expected 2704). `Fax4Decode'

操作系统:SUSE10 SP1
ImageMagick:ImageMagick-6.4.4-10
libtiff:tiff-3.8.2
gcc:gcc-4.1.2_20070115-0.11
代码如下,请高手指点:

/**
* shell>gcc -I/usr/local/ImageMagick/include/ImageMagick -L/usr/local/ImageMagick/lib -lMagick++ -o test test.cpp
*/

#include <iostream>
#include <sstream>
#include <Magick++.h>
   
using namespace std;
using namespace Magick;

string PingImage( string file_name )
{
    Image image;
    try
    {
        image.ping( file_name );        
    }
    catch( Warning &E )
    {
    cerr << "Ping Warning:" << E.what() << endl;
    }
    catch( Exception &E )
    {   
        return "Ping Error:"+string(E.what());
    }
    return "";
}

string RenderImage( string file_name, string type, double size, double angle)
{
    Image image;
    Blob blob;   
    string msg;

    if((msg = PingImage(file_name)) != "")
    {
        return msg;
    }
    cerr << "Read Image Start..." <<endl;
    try
    {
        image.read(file_name);
    }
    catch( Warning &E )
    {
        cerr << "Read Warning:" << E.what() <<endl;
    }
    catch( Exception &E )
    {
        cerr << "Read Error:" << E.what() << endl;
        return string(E.what());
    }

    image.magick( type.c_str() );
    if( strcasecmp(type.c_str(),"TIFF") == 0 ||  strcasecmp(type.c_str(),"TIF") == 0 )
        image.compressType(Group4Compression);
    else
    {               
        image.type(PaletteType);
        image.depth(8);
        image.quantizeColors(32);
    }
    if( size!=0 )
    {
        ostringstream str;
        str << size;
        cerr << "size:" << str.str().c_str()<< endl;
        image.zoom(str.str().c_str());
    }
    if( angle!=0 )
        image.rotate(angle);
    cerr << "angle:" << angle << endl;
    image.write( &blob );
    Image image_from_blob(blob);
    image_from_blob.write("image_from_blob.png");

    return string((char *)blob.data(),(long)blob.length());
}

int main(int, char* argV[])
{
        char *filename;
        int filename_len;
        char *type1;
        int type_len;
        double size;
        double angle;
        
        strcpy(filename,"001.TIF");               
               
        string img = RenderImage(string(filename),"png", 0, 0);        
}

另外:将此代码作为php的扩展模块使用时,提示如下错误,然后程序直接退出了。try...catch{Warning &E}或catch( Magick::WarningCoder &warning )
根本捕捉不到错误。
terminate called after throwing an instance of 'Magick::WarningCoder' what():  ImageMagick: 001.TIF: Line length mismatch at line 0 of strip 0 (got 4410, expected 2704). `Fax4Decode'

我查了写资料,在ImageMagic网站:http://www.imagemagick.org/Magick++/Exception.html
解释说
Warnings issued by some coders.
但是还是不知道该如何处理。

论坛徽章:
0
2 [报告]
发表于 2008-11-05 16:13 |只看该作者
自己顶:wink:
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP