魔法++ - JPEG 压缩 TIFF
我在使用 Magick++(ImageMagick 的 C++ API)创建 JPEG 压缩的 TIFF 图像时遇到问题。当我按以下方式使用转换工具时,它可以工作:
convert 1.jpg -compress JPEG 1.tiff
当我想在 C++ 中执行相同操作时,它看起来像这样:
Image img("1.jpg");
img.compressType(JPEGCompression);
img.write("1.tiff");
但此代码不起作用。当它尝试生成文件“1.tiff”时,它会抛出异常:
Unhandled exception at 0x74ecb727 in test.exe: Microsoft C++ exception: Magick::ErrorCoder at memory location 0x002ffc2c..
它指向文件Thread.cpp中的第103行
这是一个错误还是有问题我的代码?
更新
我将代码更改为:
try{
Image img(Desktop+"1.jpg");
img.compressType(JPEGCompression);
img.write(Desktop+"1.tiff");
}catch(Exception e){
cout << e.what() << endl;
}
输出: test.exe: CompressionNotSupported `JPEG' @ error/tiff.c/WriteTIFFImage/2611
所以......它似乎不受支持。问题是:为什么他的转换工具支持它呢?有人知道怎么做吗?
更新
我创建了一个空的新项目,重新编译ImageMagick,然后添加以下设置:
附加包含目录:
c:/imagemagick/magick++/lib;c:/imagemagick/
附加lib目录:
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;
然后尝试运行以下代码:
#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;
}
它起作用了!全部使用VS2010。我不知道为什么它在具有相同设置的其他项目中不起作用......
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 work. 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 ImageMagick 图像格式,您需要 ImageMagick 图像格式 ijg.org/files/" rel="nofollow">jpegsrc.v8c.tar.gz 用于 jpeg 支持。您必须链接
libjpeg
和libtiff
才能使其正常工作。您可以使用此命令创建所有必要的链接器标志:对我来说,以下代码正在运行:
使用此编译器命令:
更新:我刚刚看到您的错误是由您的 tiff 库引起的。 ImageMagick 使用
TIFFGetConfiguredCODECs()
获取支持的压缩编解码器。所以你的 tiff 库必须支持 JPEG 压缩。也许你可以尝试更新你的 tiff 库。According to ImageMagick Image Formats you need the jpegsrc.v8c.tar.gz for jpeg suppport. You have to link with
libjpeg
andlibtiff
to get it working. You can create all necessary linker flags using this command:For me the following code is working:
Using this compiler command:
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.