【文件属性】:
文件名称:Magick++.cpp
文件大小:8KB
文件格式:CPP
更新时间:2023-08-20 07:43:45
linuxC++绘图 图片合成
linux下采用开源库Magick++实现图片合成,图片添加中英文字体:需要自己下载编译Magick++,如下为部分代码,下载可看完整代码
#include
#include
#include
#include
#include
#define MAGICKCORE_QUANTUM_DEPTH 16
#define MAGICKCORE_HDRI_ENABLE 1
//#define _GLIBCXX_USE_CXX11_ABI 0L
#define BI_RGB 0L
using namespace std;
using namespace Magick;
bool bCHMixBack(char *JiGuan, char *DateBegain,char *DateEnd,char *BackGroundpic,char *toPic);
bool bCHMixBack(char *JiGuan, char *DateBegain,char *DateEnd,char *BackGroundpic,char *toPic)
{
std::vector draws;
Magick::Image img;
img.read( BackGroundpic );
printf(BackGroundpic);
printf("\nBackGroundpic end\n");
//draws.push_back(Magick::DrawableFont("黑体",(Magick::StyleType)AnyStyle,600,(Magick::StretchType)AnyStretch)); //设置字体 宋体 黑体 微软雅黑//
/* Magick::DrawableFont Font = Magick::DrawableFont("黑体",(Magick::StyleType)NormalStyle,400,(Magick::StretchType)AnyStretch);//"/usr/share/fonts/simhei.ttf"
draws.push_back(Font);
draws.push_back(Magick::DrawablePointSize(22)); //设置字体大小
draws.push_back(Magick::DrawableFillColor(Magick::Color("black")));//字体颜色
char szDate[255]={0};
sprintf(szDate,"%s-%s",DateBegain,DateEnd);
draws.push_back(Magick::DrawableText(200,276,"33"));
//draws.push_back(Magick::DrawableText(200,276,szDate));
//draws.push_back(Magick::DrawableText(200,240,JiGuan));
printf("\n");
printf(szDate);
printf("\n");
printf(JiGuan);
printf("\n++++bCHMixBack img.draw(draws)\n");
img.draw(draws);
*/
string family_ = "黑体";
img.fontFamily(family_);
img.fontPointsize(22);
img.fontWeight(600);
img.fillColor(Magick::Color("black"));
img.fontStyle((Magick::StyleType)NormalStyle);
Magick::DrawableText text(200,276,"字体颜色");
img.draw(text);
printf("\n++++bCHMixBackimg.draw(draws) End\n");
int len = strlen(toPic);
if(toPic[len-5]=='.')
{
len -=4;
}
else if(toPic[len-4]=='.')
{
len -=3;
}
else
{
return false;
}
printf(toPic);
img.magick(toPic+len);
printf("==");
img.write(toPic);
printf("\n++++bCHMixBackimg.write(toPic) End\n");
return true;
}