解决水印不支持中文的问题
This commit is contained in:
parent
5dede65275
commit
e74e0aeba6
|
@ -138,9 +138,9 @@ HGResult CvxText::DrawString(HGImage image, const HGChar* text, HGColor color, H
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if defined(HG_CMP_MSC)
|
#if defined(HG_CMP_MSC)
|
||||||
DrawChar(image, pUnicode[i], locationX + vPos[i].left, locationY + vPos[i].top, color, fontSize, bold, italic);
|
DrawChar(image, pUnicode[i], color, locationX + vPos[i].left, locationY + vPos[i].top, fontSize, bold, italic);
|
||||||
#else
|
#else
|
||||||
DrawChar(image, pUnicodeEx[i], locationX + vPos[i].left, locationY + vPos[i].top, color, fontSize, bold, italic);
|
DrawChar(image, pUnicodeEx[i], color, locationX + vPos[i].left, locationY + vPos[i].top, fontSize, bold, italic);
|
||||||
#endif
|
#endif
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
@ -149,17 +149,18 @@ HGResult CvxText::DrawString(HGImage image, const HGChar* text, HGColor color, H
|
||||||
|
|
||||||
if (underline)
|
if (underline)
|
||||||
{
|
{
|
||||||
HGImgProc_ImageDrawLine(image, locationX, locationY + height - 1, locationX + width, locationY + height - 1, 1, color);
|
HGImgProc_ImageDrawLine(image, locationX, locationY + height - 1,
|
||||||
|
locationX + width, locationY + height - 1, color, 1, HGIMGPROC_LINETYPE_SOLID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strikeout)
|
if (strikeout)
|
||||||
{
|
{
|
||||||
if (underline)
|
if (underline)
|
||||||
HGImgProc_ImageDrawLine(image, locationX, locationY + (height - 1) / 2,
|
HGImgProc_ImageDrawLine(image, locationX, locationY + (height - 1) / 2,
|
||||||
locationX + width, locationY + (height - 1) / 2, 1, color);
|
locationX + width, locationY + (height - 1) / 2, color, 1, HGIMGPROC_LINETYPE_SOLID);
|
||||||
else
|
else
|
||||||
HGImgProc_ImageDrawLine(image, locationX, locationY + height / 2,
|
HGImgProc_ImageDrawLine(image, locationX, locationY + height / 2,
|
||||||
locationX + width, locationY + height / 2, 1, color);
|
locationX + width, locationY + height / 2, color, 1, HGIMGPROC_LINETYPE_SOLID);
|
||||||
}
|
}
|
||||||
|
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
|
@ -243,7 +244,7 @@ void CvxText::MeasureChar(HGUInt wc, HGUInt fontSize, HGBool bold, HGBool italic
|
||||||
{
|
{
|
||||||
FT_Matrix matrix;
|
FT_Matrix matrix;
|
||||||
matrix.xx = 0x10000L;
|
matrix.xx = 0x10000L;
|
||||||
matrix.xy = 0.5f * 0x10000L;
|
matrix.xy = 0.4f * 0x10000L;
|
||||||
matrix.yx = 0;
|
matrix.yx = 0;
|
||||||
matrix.yy = 0x10000L;
|
matrix.yy = 0x10000L;
|
||||||
FT_Outline_Transform(&m_face->glyph->outline, &matrix);
|
FT_Outline_Transform(&m_face->glyph->outline, &matrix);
|
||||||
|
@ -336,9 +337,11 @@ void CvxText::GetStringLocation(const HGChar* text, HGUInt fontSize, HGBool bold
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CvxText::DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color, HGUInt fontSize, HGBool bold, HGBool italic)
|
void CvxText::DrawChar(HGImage image, HGUInt wc, HGColor color, HGInt x, HGInt y, HGUInt fontSize, HGBool bold, HGBool italic)
|
||||||
{
|
{
|
||||||
assert(NULL != m_face);
|
assert(NULL != m_face);
|
||||||
|
assert(NULL != image);
|
||||||
|
assert(0 != fontSize);
|
||||||
|
|
||||||
FT_Set_Pixel_Sizes(m_face, fontSize, fontSize);
|
FT_Set_Pixel_Sizes(m_face, fontSize, fontSize);
|
||||||
FT_UInt glyph_index = FT_Get_Char_Index(m_face, wc);
|
FT_UInt glyph_index = FT_Get_Char_Index(m_face, wc);
|
||||||
|
@ -358,7 +361,7 @@ void CvxText::DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color
|
||||||
{
|
{
|
||||||
FT_Matrix matrix;
|
FT_Matrix matrix;
|
||||||
matrix.xx = 0x10000L;
|
matrix.xx = 0x10000L;
|
||||||
matrix.xy = 0.5f * 0x10000L;
|
matrix.xy = 0.4f * 0x10000L;
|
||||||
matrix.yx = 0;
|
matrix.yx = 0;
|
||||||
matrix.yy = 0x10000L;
|
matrix.yy = 0x10000L;
|
||||||
FT_Outline_Transform(&m_face->glyph->outline, &matrix);
|
FT_Outline_Transform(&m_face->glyph->outline, &matrix);
|
||||||
|
|
|
@ -24,7 +24,7 @@ private:
|
||||||
void MeasureChar(HGUInt wc, HGUInt fontSize, HGBool bold, HGBool italic, FT_BBox& acbox);
|
void MeasureChar(HGUInt wc, HGUInt fontSize, HGBool bold, HGBool italic, FT_BBox& acbox);
|
||||||
void GetStringLocation(const HGChar* text, HGUInt fontSize, HGBool bold, HGBool underline, HGBool italic, HGBool strikeout,
|
void GetStringLocation(const HGChar* text, HGUInt fontSize, HGBool bold, HGBool underline, HGBool italic, HGBool strikeout,
|
||||||
HGUInt &width, HGUInt &height, std::vector<HGRect> &vPos);
|
HGUInt &width, HGUInt &height, std::vector<HGRect> &vPos);
|
||||||
void DrawChar(HGImage image, HGUInt wc, HGInt x, HGInt y, HGColor color, HGUInt fontSize, HGBool bold, HGBool italic);
|
void DrawChar(HGImage image, HGUInt wc, HGColor color, HGInt x, HGInt y, HGUInt fontSize, HGBool bold, HGBool italic);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FT_Library m_library;
|
FT_Library m_library;
|
||||||
|
|
|
@ -366,32 +366,23 @@ HGResult HGAPI HGImgProc_ImageBlankCheck(HGImage image, const HGImgBlankCheckPar
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, HGUInt lineWidth, HGColor color)
|
HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2,
|
||||||
|
HGColor color, HGUInt width, HGUInt type)
|
||||||
{
|
{
|
||||||
if (NULL == image || 0 == lineWidth)
|
if (NULL == image || 0 == width || type < HGIMGPROC_LINETYPE_SOLID || type > HGIMGPROC_LINETYPE_DASH)
|
||||||
{
|
{
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
HGImageInfo imgInfo;
|
HGImageInfo imgInfo;
|
||||||
HGBase_GetImageInfo(image, &imgInfo);
|
HGBase_GetImageInfo(image, &imgInfo);
|
||||||
uint32_t type = imgInfo.type;
|
if (HGBASE_IMGTYPE_BINARY == imgInfo.type || HGBASE_IMGTYPE_GRAY == imgInfo.type)
|
||||||
|
|
||||||
HGByte* data = NULL;
|
|
||||||
HGBase_GetImageData(image, &data);
|
|
||||||
|
|
||||||
HGImageRoi roi;
|
|
||||||
HGBase_GetImageROI(image, &roi);
|
|
||||||
HGUInt roiWidth = roi.right - roi.left;
|
|
||||||
HGUInt roiHeight = roi.bottom - roi.top;
|
|
||||||
|
|
||||||
if (HGBASE_IMGTYPE_BINARY == type || HGBASE_IMGTYPE_GRAY == type)
|
|
||||||
{
|
{
|
||||||
HGImage imageTmp = NULL;
|
HGImage imageTmp = NULL;
|
||||||
HGResult ret = HGBase_CloneImage(image, HGBASE_IMGTYPE_RGB, 0, &imageTmp);
|
HGResult ret = HGBase_CloneImage(image, HGBASE_IMGTYPE_RGB, 0, &imageTmp);
|
||||||
if (HGBASE_ERR_OK == ret)
|
if (HGBASE_ERR_OK == ret)
|
||||||
{
|
{
|
||||||
ret = HGImgProc_ImageDrawLine(imageTmp, x1, y1, x2, y2, lineWidth, color);
|
ret = HGImgProc_ImageDrawLine(imageTmp, x1, y1, x2, y2, color, width, type);
|
||||||
if (HGBASE_ERR_OK == ret)
|
if (HGBASE_ERR_OK == ret)
|
||||||
{
|
{
|
||||||
ret = HGBase_CopyImage(imageTmp, image);
|
ret = HGBase_CopyImage(imageTmp, image);
|
||||||
|
@ -403,8 +394,16 @@ HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HGByte* data = NULL;
|
||||||
|
HGBase_GetImageData(image, &data);
|
||||||
|
|
||||||
|
HGImageRoi roi;
|
||||||
|
HGBase_GetImageROI(image, &roi);
|
||||||
|
HGUInt roiWidth = roi.right - roi.left;
|
||||||
|
HGUInt roiHeight = roi.bottom - roi.top;
|
||||||
|
|
||||||
uint32_t channels = 3;
|
uint32_t channels = 3;
|
||||||
if (HGBASE_IMGTYPE_BGRA == type || HGBASE_IMGTYPE_RGBA == type)
|
if (HGBASE_IMGTYPE_BGRA == imgInfo.type || HGBASE_IMGTYPE_RGBA == imgInfo.type)
|
||||||
channels = 4;
|
channels = 4;
|
||||||
|
|
||||||
uint8_t* p = data + roi.top * imgInfo.widthStep + roi.left * channels;
|
uint8_t* p = data + roi.top * imgInfo.widthStep + roi.left * channels;
|
||||||
|
@ -423,14 +422,14 @@ HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt
|
||||||
HGUInt r = HG_GETCOLOR_R(color);
|
HGUInt r = HG_GETCOLOR_R(color);
|
||||||
HGUInt g = HG_GETCOLOR_G(color);
|
HGUInt g = HG_GETCOLOR_G(color);
|
||||||
HGUInt b = HG_GETCOLOR_B(color);
|
HGUInt b = HG_GETCOLOR_B(color);
|
||||||
if (HGBASE_IMGTYPE_BGR == type || HGBASE_IMGTYPE_BGRA == type)
|
if (HGBASE_IMGTYPE_BGR == imgInfo.type || HGBASE_IMGTYPE_BGRA == imgInfo.type)
|
||||||
{
|
{
|
||||||
r = HG_GETCOLOR_B(color);
|
r = HG_GETCOLOR_B(color);
|
||||||
g = HG_GETCOLOR_G(color);
|
g = HG_GETCOLOR_G(color);
|
||||||
b = HG_GETCOLOR_R(color);
|
b = HG_GETCOLOR_R(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
cvLine(pImg, cvPoint(x1, y1), cvPoint(x2, y2), cvScalar(r, g, b), lineWidth);
|
cvLine(pImg, cvPoint(x1, y1), cvPoint(x2, y2), cvScalar(r, g, b), width);
|
||||||
cvReleaseImageHeader(&pImg);
|
cvReleaseImageHeader(&pImg);
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,30 @@
|
||||||
/* 双线性插值 */
|
/* 双线性插值 */
|
||||||
#define HGIMGPROC_INTERPOTYPE_LINEAR 2L
|
#define HGIMGPROC_INTERPOTYPE_LINEAR 2L
|
||||||
|
|
||||||
/* 水印位置 */
|
/* 线条类型-实线 */
|
||||||
|
#define HGIMGPROC_LINETYPE_SOLID 1L
|
||||||
|
/* 线条类型-虚线 */
|
||||||
|
#define HGIMGPROC_LINETYPE_DASH 2L
|
||||||
|
|
||||||
|
/* 水印位置-左侧 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_LEFT 1L
|
#define HGIMGPROC_WMPOSTYPE_LEFT 1L
|
||||||
|
/* 水印位置-上侧 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_TOP 2L
|
#define HGIMGPROC_WMPOSTYPE_TOP 2L
|
||||||
|
/* 水印位置-右侧 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_RIGHT 3L
|
#define HGIMGPROC_WMPOSTYPE_RIGHT 3L
|
||||||
|
/* 水印位置-下侧 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_BOTTOM 4L
|
#define HGIMGPROC_WMPOSTYPE_BOTTOM 4L
|
||||||
|
/* 水印位置-左上 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_LEFTTOP 5L
|
#define HGIMGPROC_WMPOSTYPE_LEFTTOP 5L
|
||||||
|
/* 水印位置-右上 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_RIGHTTOP 6L
|
#define HGIMGPROC_WMPOSTYPE_RIGHTTOP 6L
|
||||||
|
/* 水印位置-左下 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_LEFTBOTTOM 7L
|
#define HGIMGPROC_WMPOSTYPE_LEFTBOTTOM 7L
|
||||||
|
/* 水印位置-右下 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_RIGHTBOTTOM 8L
|
#define HGIMGPROC_WMPOSTYPE_RIGHTBOTTOM 8L
|
||||||
|
/* 水印位置-中间 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_CENTER 9L
|
#define HGIMGPROC_WMPOSTYPE_CENTER 9L
|
||||||
|
/* 水印位置-自定义 */
|
||||||
#define HGIMGPROC_WMPOSTYPE_LOCATION 10L
|
#define HGIMGPROC_WMPOSTYPE_LOCATION 10L
|
||||||
|
|
||||||
/* 自动裁剪参数 */
|
/* 自动裁剪参数 */
|
||||||
|
@ -112,9 +126,20 @@ HGEXPORT HGResult HGAPI HGImgProc_ImageAutoCrop(HGImage image, HGBool autoCrop,
|
||||||
*/
|
*/
|
||||||
HGEXPORT HGResult HGAPI HGImgProc_ImageBlankCheck(HGImage image, const HGImgBlankCheckParam *param, HGBool *blank);
|
HGEXPORT HGResult HGAPI HGImgProc_ImageBlankCheck(HGImage image, const HGImgBlankCheckParam *param, HGBool *blank);
|
||||||
|
|
||||||
/* 画线
|
/* 图像画线
|
||||||
|
* 1) image: in, 图像句柄
|
||||||
|
* 2) x1: in, 第一个点x坐标
|
||||||
|
* 3) y1: in, 第一个点y坐标
|
||||||
|
* 4) x2: in, 第二个点x坐标
|
||||||
|
* 5) y2: in, 第二个点y坐标
|
||||||
|
* 6) color: in, 颜色
|
||||||
|
* 7) width: in, 线宽
|
||||||
|
* 8) type: in, 表示线类型, 参见HGIMGPROC_LINETYPE_*
|
||||||
|
* 说明:
|
||||||
|
* 1) 操作的只是图像的ROI区域
|
||||||
*/
|
*/
|
||||||
HGEXPORT HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2, HGUInt lineWidth, HGColor color);
|
HGEXPORT HGResult HGAPI HGImgProc_ImageDrawLine(HGImage image, HGInt x1, HGInt y1, HGInt x2, HGInt y2,
|
||||||
|
HGColor color, HGUInt width, HGUInt type);
|
||||||
|
|
||||||
/* 添加图像水印
|
/* 添加图像水印
|
||||||
* 1) image: in, 图像句柄
|
* 1) image: in, 图像句柄
|
||||||
|
|
|
@ -3602,6 +3602,22 @@ namespace ver_2
|
||||||
|
|
||||||
FindClose(hFind);
|
FindClose(hFind);
|
||||||
#else
|
#else
|
||||||
|
DIR* dir = opendir(m_bindFolder.c_str());
|
||||||
|
if (NULL != dir)
|
||||||
|
{
|
||||||
|
struct dirent* dire = NULL;
|
||||||
|
while (dire = readdir(dir))
|
||||||
|
{
|
||||||
|
char fileName[256];
|
||||||
|
sprintf(fileName, "%s%s", m_bindFolder.c_str(), dire->d_name);
|
||||||
|
if (!IS_DIR(fileName))
|
||||||
|
{
|
||||||
|
HGBase_DeleteFile(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(dir);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1775,7 +1775,7 @@ namespace ver_2
|
||||||
assert(NULL != json);
|
assert(NULL != json);
|
||||||
|
|
||||||
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
std::string imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
||||||
std::string text = GetJsonStringValue(json, "text");
|
std::string text = Utf8ToStdString(GetJsonStringValue(json, "text"));
|
||||||
|
|
||||||
bool find;
|
bool find;
|
||||||
std::string textColor = GetJsonStringValue(json, "text_color", &find);
|
std::string textColor = GetJsonStringValue(json, "text_color", &find);
|
||||||
|
@ -4129,7 +4129,7 @@ namespace ver_2
|
||||||
assert(NULL != json);
|
assert(NULL != json);
|
||||||
|
|
||||||
int imageIndex = GetJsonIntValue(json, "image_index");
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
||||||
std::string text = GetJsonStringValue(json, "text");
|
std::string text = Utf8ToStdString(GetJsonStringValue(json, "text"));
|
||||||
|
|
||||||
bool find;
|
bool find;
|
||||||
std::string textColor = GetJsonStringValue(json, "text_color", &find);
|
std::string textColor = GetJsonStringValue(json, "text_color", &find);
|
||||||
|
|
|
@ -369,7 +369,7 @@
|
||||||
socket.send(JSON.stringify({
|
socket.send(JSON.stringify({
|
||||||
'func':'local_image_add_watermark',
|
'func':'local_image_add_watermark',
|
||||||
'image_path':'D:\\1.jpg',
|
'image_path':'D:\\1.jpg',
|
||||||
'text':'1234567890',
|
'text':'扫描仪,1234qwer',
|
||||||
'text_color':'#FF0000',
|
'text_color':'#FF0000',
|
||||||
'text_pos':'right_top',
|
'text_pos':'right_top',
|
||||||
'font_size':60,
|
'font_size':60,
|
||||||
|
|
Loading…
Reference in New Issue