(1)編譯
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$ g++ `Magick++-config --cxxflags --cppflags` -I/usr/local/include/ImageMagick-7 mtile.c `Magick++-config --ldflags --libs` -L/usr/local/zlib/lib -lz -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic -lm -o mtile
(2)執行
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$ ./mtile 312x2689-4x3-cw1.png 312x2683-4x3-cw3.png 312x2680-4x3-cw4.png 312x2686-4x3-cw2.png 使用四個來源圖檔 [1:左上312x2689-4x3-cw1.png][2:右上312x2683-4x3-cw3.png] [4:左下312x2680-4x3-cw4.png][3:右下312x2686-4x3-cw2.png] 上下左右四原始圖寬高皆為 width=1266 height=951 合併四圖後的寬高為 width=2532 height=1902 輸出四圖合併後的圖檔 mtile.jpg 成功! treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$
(3)程式碼 : mtile.c
treehrt@treehrt-BM6AE-BM1AE-BP1AE:~/lake$ cat mtile.c //g++ `Magick++-config --cxxflags --cppflags` -I/usr/local/include/ImageMagick-7 mtile.c `Magick++-config --ldflags --libs` -L/usr/local/zlib/lib -lz -Wall `pkg-config --cflags --libs gtk+-3.0` -export-dynamic -lm -o mtile // https://people.cs.clemson.edu/~dhouse/courses/405/notes/Magick++_tutorial.pdf #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <Magick++.h>
using namespace Magick; void mtile(char *fname1,char *fname2,char *fname3,char *fname4){ Image im(fname1); Image im1(fname1); Image im2(fname2); Image im3(fname3); Image im4(fname4); Geometry size = im.size(); double rw=2; double rh=2; int w=size.width(); int h=size.height(); im.resize(Magick::Geometry(size.width()*rw,size.height()*rh)); printf("上下左右四原始圖寬高皆為 width=%d height=%d\n",(int)size.width(),(int)size.height()); printf("合併四圖後的寬高為 width=%.0f height=%.0f\n",size.width()*rw,size.height()*rh); im.composite(im1, 0, 0, OverCompositeOp); im.composite(im2, w-1, 0, OverCompositeOp); im.composite(im3, w, h, OverCompositeOp); im.composite(im4, 0, h-1, OverCompositeOp); im.write("mtile.jpg"); printf("輸出四圖合併後的圖檔 mtile.jpg 成功!\n"); }
int main(int argc, char *argv[]) { if (argc!=5) { printf("圖磚合併程式的語法 ./mtile 1.png 2.png 3.png 4.png\n"); printf("輸出併圖結果檔為mtile.jpg\n"); exit(-1); } printf("使用四個來源圖檔\n[1:左上%20s][2:右上%20s]\n[4:左下%20s][3:右下%20s]\n",argv[1],argv[2],argv[3],argv[4]); mtile(argv[1],argv[2],argv[3],argv[4]); }

|