开发者

Magick++ - JPEG compressed TIFF

I have a problem creating a TIFF image with a JPEG compression using Magick++, the C++ API of ImageMagick. When I use the convert tool the following way, it works:

convert 1.jpg -compress JPEG 1.tiff

When I want to do the same in C++, it looks like this:

Image img("1.jpg");
img.compressType(JPEGCompression);
img.write("1.tiff");

But this code does not w开发者_C百科ork. It throws an exception when it tries to generate the file "1.tiff":

Unhandled exception at 0x74ecb727 in test.exe: Microsoft C++ exception: Magick::ErrorCoder at memory location 0x002ffc2c..

It points to Line 103 in file Thread.cpp

Is this a bug or is something wrong with my code?

Update

I changed the code to this:

try{
    Image img(Desktop+"1.jpg");
    img.compressType(JPEGCompression);
    img.write(Desktop+"1.tiff");
}catch(Exception e){
    cout << e.what() << endl;
}

Output: test.exe: CompressionNotSupported `JPEG' @ error/tiff.c/WriteTIFFImage/2611

So... it seems to be not supported. The question is: Why does he convert tool support it then? Does someone know a way to do it?

Update

I've created an empty new project, recompiled ImageMagick and then added the following settings:

additional include dirs:

c:/imagemagick/magick++/lib;c:/imagemagick/

additional lib dirs:

c:/imagemagick/visualmagick/lib/

libs:

CORE_RL_bzlib_.lib;CORE_RL_coders_.lib;CORE_RL_filters_.lib;CORE_RL_jbig_.lib;CORE_RL_jp2_.lib;CORE_RL_jpeg_.lib;CORE_RL_lcms_.lib;CORE_RL_libxml_.lib;CORE_RL_magick_.lib;CORE_RL_Magick++_.lib;CORE_RL_png_.lib;CORE_RL_tiff_.lib;CORE_RL_ttf_.lib;CORE_RL_wand_.lib;CORE_RL_xlib_.lib;CORE_RL_zlib_.lib;CORE_RL_wmf_.lib;X11.lib;Xext.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;wsock32.lib;winmm.lib;

and then tried to run the following code:

#include <iostream>
#include <Magick++.h>

using namespace std;
using namespace Magick;

int main() {
    Image img("c:/users/patrik stutz/Desktop/1.jpg");
    img.compressType(JPEGCompression);
    img.write("c:/users/patrik stutz/Desktop/1.tiff");
    return 0;
}

And it worked!! All using VS2010. I have no clue why it didn´t work in my other project with the same settings...


According to ImageMagick Image Formats you need the jpegsrc.v8c.tar.gz for jpeg suppport. You have to link with libjpeg and libtiff to get it working. You can create all necessary linker flags using this command:

Magick++-config --cppflags --cxxflags --ldflags --libs

For me the following code is working:

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

int main() {
    Image img("1.jpg");
    img.compressType(JPEGCompression);
    img.write("1.tiff");
    return 0;
}

Using this compiler command:

g++ -L/usr/lib -L/usr/lib/X11 -o"testim"  ./src/testim.o -lMagick++ -lMagickWand -lMagickCore -llcms -ltiff -lfreetype -ljpeg -llqr-1 -lglib-2.0 -lfontconfig -lXext -lSM -lICE -lX11 -lXt -lbz2 -lz -lm -lgomp -lpthread -lltdl

Update: I just saw that your error is originated by your tiff library. ImageMagick uses TIFFGetConfiguredCODECs() the get the supported compression codecs. So your tiff library has to support JPEG compression. Maybe you can try to update your tiff library.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜