websdk增加手动裁剪功能
This commit is contained in:
parent
67842303b9
commit
c3fbe9d0ba
Binary file not shown.
|
@ -72,6 +72,7 @@ struct HGGifWriterImpl
|
||||||
{
|
{
|
||||||
int savedCount = m_gifFile->ImageCount;
|
int savedCount = m_gifFile->ImageCount;
|
||||||
SavedImage* savedImages = m_gifFile->SavedImages;
|
SavedImage* savedImages = m_gifFile->SavedImages;
|
||||||
|
|
||||||
//关闭GIF并释放相关存储。
|
//关闭GIF并释放相关存储。
|
||||||
EGifSpew(m_gifFile);
|
EGifSpew(m_gifFile);
|
||||||
|
|
||||||
|
@ -84,12 +85,15 @@ struct HGGifWriterImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sp->RasterBits != NULL)
|
if (sp->RasterBits != NULL)
|
||||||
free((char*)sp->RasterBits);
|
{
|
||||||
|
free(sp->RasterBits);
|
||||||
|
sp->RasterBits = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
GifFreeExtensions(&sp->ExtensionBlockCount, &sp->ExtensionBlocks);
|
GifFreeExtensions(&sp->ExtensionBlockCount, &sp->ExtensionBlocks);
|
||||||
}
|
}
|
||||||
|
|
||||||
free((char*)savedImages);
|
free(savedImages);
|
||||||
savedImages = NULL;
|
savedImages = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -475,6 +479,7 @@ HGResult HGAPI HGImgFmt_CloseGifReader(HGGifReader reader)
|
||||||
static HGResult LoadGifImage(HGGifReaderImpl* gifReaderImpl, HGUInt &interval)
|
static HGResult LoadGifImage(HGGifReaderImpl* gifReaderImpl, HGUInt &interval)
|
||||||
{
|
{
|
||||||
assert(NULL != gifReaderImpl);
|
assert(NULL != gifReaderImpl);
|
||||||
|
interval = 0;
|
||||||
|
|
||||||
int transColor = -1;
|
int transColor = -1;
|
||||||
unsigned int loopCount = 0;
|
unsigned int loopCount = 0;
|
||||||
|
|
|
@ -1147,6 +1147,53 @@ namespace ver_2
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ManagerV2::LocalImageClip(const std::string& imagePath, int x, int y, int width, int height,
|
||||||
|
bool temp, std::string& outImagePath, std::string& errInfo)
|
||||||
|
{
|
||||||
|
outImagePath.clear();
|
||||||
|
errInfo = "错误";
|
||||||
|
|
||||||
|
if (imagePath.empty() || x < 0 || y < 0 || width <= 0 || height <= 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int ret = -1;
|
||||||
|
HGImage image = NULL;
|
||||||
|
HGImgFmt_LoadImage(imagePath.c_str(), 0, NULL, 0, HGBASE_IMGORIGIN_TOP, &image);
|
||||||
|
if (NULL != image)
|
||||||
|
{
|
||||||
|
HGImageRoi roi;
|
||||||
|
roi.left = x;
|
||||||
|
roi.top = y;
|
||||||
|
roi.right = roi.left + width;
|
||||||
|
roi.bottom = roi.top + height;
|
||||||
|
|
||||||
|
if (HGBASE_ERR_OK == HGBase_SetImageROI(image, &roi))
|
||||||
|
{
|
||||||
|
HGImage image2 = NULL;
|
||||||
|
if (HGBASE_ERR_OK == HGBase_CloneImage(image, 0, 0, &image2))
|
||||||
|
{
|
||||||
|
if (0 == SaveImage(image2, temp, outImagePath))
|
||||||
|
{
|
||||||
|
if (!temp)
|
||||||
|
{
|
||||||
|
m_saveFilePathList.push_back(outImagePath);
|
||||||
|
RestoreSaveFilePathList(m_saveFilePathList);
|
||||||
|
}
|
||||||
|
|
||||||
|
errInfo.clear();
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
HGBase_DestroyImage(image2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HGBase_DestroyImage(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int ManagerV2::InitDevice(std::string& errInfo)
|
int ManagerV2::InitDevice(std::string& errInfo)
|
||||||
{
|
{
|
||||||
errInfo = "错误";
|
errInfo = "错误";
|
||||||
|
|
|
@ -176,6 +176,9 @@ namespace ver_2
|
||||||
int x, int y, int width, int height, bool temp, std::string& outImagePath, std::string& errInfo);
|
int x, int y, int width, int height, bool temp, std::string& outImagePath, std::string& errInfo);
|
||||||
// 图像方向校正
|
// 图像方向校正
|
||||||
int LocalImageDirectionCorrect(const std::string& imagePath, bool temp, std::string& outImagePath, std::string& errInfo);
|
int LocalImageDirectionCorrect(const std::string& imagePath, bool temp, std::string& outImagePath, std::string& errInfo);
|
||||||
|
// 裁剪图像
|
||||||
|
int LocalImageClip(const std::string& imagePath, int x, int y, int width, int height,
|
||||||
|
bool temp, std::string& outImagePath, std::string& errInfo);
|
||||||
|
|
||||||
// 设备初始化
|
// 设备初始化
|
||||||
int InitDevice(std::string& errInfo);
|
int InitDevice(std::string& errInfo);
|
||||||
|
|
|
@ -285,6 +285,10 @@ namespace ver_2
|
||||||
{
|
{
|
||||||
ImageDirectionCorrect(json, func);
|
ImageDirectionCorrect(json, func);
|
||||||
}
|
}
|
||||||
|
else if ("local_image_clip" == func || "base64_image_clip" == func || "image_clip" == func)
|
||||||
|
{
|
||||||
|
ImageClip(json, func);
|
||||||
|
}
|
||||||
else if ("upload_local_file" == func)
|
else if ("upload_local_file" == func)
|
||||||
{
|
{
|
||||||
UploadLocalFile(json);
|
UploadLocalFile(json);
|
||||||
|
@ -2091,6 +2095,88 @@ namespace ver_2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WSUser::ImageClip(cJSON* json, const std::string& func)
|
||||||
|
{
|
||||||
|
assert(NULL != json);
|
||||||
|
|
||||||
|
int x = GetJsonIntValue(json, "x");
|
||||||
|
int y = GetJsonIntValue(json, "y");
|
||||||
|
int width = GetJsonIntValue(json, "width");
|
||||||
|
int height = GetJsonIntValue(json, "height");
|
||||||
|
bool find = false;
|
||||||
|
bool localSave = GetJsonBoolValue(json, "local_save", &find);
|
||||||
|
if (!find)
|
||||||
|
localSave = true;
|
||||||
|
|
||||||
|
std::string imagePath;
|
||||||
|
if ("image_clip" == func)
|
||||||
|
{
|
||||||
|
int imageIndex = GetJsonIntValue(json, "image_index");
|
||||||
|
std::string errInfo2;
|
||||||
|
GetManager()->SaveImage(imageIndex, true, imagePath, errInfo2);
|
||||||
|
}
|
||||||
|
else if ("local_image_clip" == func)
|
||||||
|
{
|
||||||
|
imagePath = Utf8ToStdString(GetJsonStringValue(json, "image_path"));
|
||||||
|
}
|
||||||
|
else if ("base64_image_clip" == func)
|
||||||
|
{
|
||||||
|
std::string imageBase64 = GetJsonStringValue(json, "image_base64");
|
||||||
|
std::string errInfo2;
|
||||||
|
GetManager()->SaveLocalImage(imageBase64, true, imagePath, errInfo2);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string outImagePath;
|
||||||
|
std::string errInfo;
|
||||||
|
int ret = GetManager()->LocalImageClip(imagePath, x, y, width, height, !localSave, outImagePath, errInfo);
|
||||||
|
|
||||||
|
if ("image_clip" == func || "base64_image_clip" == func)
|
||||||
|
{
|
||||||
|
HGBase_DeleteFile(imagePath.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string outImageBase64;
|
||||||
|
bool getBase64 = GetJsonBoolValue(json, "get_base64");
|
||||||
|
if (0 == ret && getBase64)
|
||||||
|
{
|
||||||
|
std::string errInfo2;
|
||||||
|
GetManager()->LoadLocalImage(outImagePath, outImageBase64, errInfo2);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool findIden = false;
|
||||||
|
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||||
|
|
||||||
|
cJSON* retJson = cJSON_CreateObject();
|
||||||
|
if (NULL != retJson)
|
||||||
|
{
|
||||||
|
cJSON_AddItemToObject(retJson, "func", cJSON_CreateString(func.c_str()));
|
||||||
|
if (findIden)
|
||||||
|
cJSON_AddItemToObject(retJson, "iden", cJSON_CreateString(iden.c_str()));
|
||||||
|
cJSON_AddItemToObject(retJson, "ret", cJSON_CreateNumber(ret));
|
||||||
|
if (0 != ret)
|
||||||
|
cJSON_AddItemToObject(retJson, "err_info", cJSON_CreateString(StdStringToUtf8(errInfo).c_str()));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (localSave)
|
||||||
|
cJSON_AddItemToObject(retJson, "image_path", cJSON_CreateString(StdStringToUtf8(outImagePath).c_str()));
|
||||||
|
else
|
||||||
|
HGBase_DeleteFile(outImagePath.c_str());
|
||||||
|
|
||||||
|
if (getBase64)
|
||||||
|
cJSON_AddItemToObject(retJson, "image_base64", cJSON_CreateString(outImageBase64.c_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
char* resp = cJSON_Print(retJson);
|
||||||
|
if (NULL != resp)
|
||||||
|
{
|
||||||
|
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||||
|
free(resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_Delete(retJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void WSUser::InitDevice(cJSON* json)
|
void WSUser::InitDevice(cJSON* json)
|
||||||
{
|
{
|
||||||
assert(NULL != json);
|
assert(NULL != json);
|
||||||
|
|
|
@ -48,6 +48,7 @@ namespace ver_2
|
||||||
void ImageAddWatermark(cJSON* json, const std::string& func);
|
void ImageAddWatermark(cJSON* json, const std::string& func);
|
||||||
void ImageDecontamination(cJSON* json, const std::string& func);
|
void ImageDecontamination(cJSON* json, const std::string& func);
|
||||||
void ImageDirectionCorrect(cJSON* json, const std::string& func);
|
void ImageDirectionCorrect(cJSON* json, const std::string& func);
|
||||||
|
void ImageClip(cJSON* json, const std::string& func);
|
||||||
|
|
||||||
void InitDevice(cJSON* json);
|
void InitDevice(cJSON* json);
|
||||||
void DeinitDevice(cJSON* json);
|
void DeinitDevice(cJSON* json);
|
||||||
|
|
|
@ -97,6 +97,12 @@
|
||||||
myCanvas.src = message['image_base64'];
|
myCanvas.src = message['image_base64'];
|
||||||
alert(msg.data);
|
alert(msg.data);
|
||||||
}
|
}
|
||||||
|
else if ("local_image_clip" == message['func'])
|
||||||
|
{
|
||||||
|
var myCanvas = document.getElementById("myCanvas");
|
||||||
|
myCanvas.src = message['image_base64'];
|
||||||
|
alert(msg.data);
|
||||||
|
}
|
||||||
else if ("init_device" == message['func'])
|
else if ("init_device" == message['func'])
|
||||||
{
|
{
|
||||||
alert(msg.data);
|
alert(msg.data);
|
||||||
|
@ -316,6 +322,12 @@
|
||||||
myCanvas.src = message['image_base64'];
|
myCanvas.src = message['image_base64'];
|
||||||
alert(msg.data);
|
alert(msg.data);
|
||||||
}
|
}
|
||||||
|
else if ("image_clip" == message['func'])
|
||||||
|
{
|
||||||
|
var myCanvas = document.getElementById("myCanvas");
|
||||||
|
myCanvas.src = message['image_base64'];
|
||||||
|
alert(msg.data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -483,6 +495,20 @@
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function LocalImageClip()
|
||||||
|
{
|
||||||
|
socket.send(JSON.stringify({
|
||||||
|
'func':'local_image_clip',
|
||||||
|
'image_path':'D:\\1.jpg',
|
||||||
|
'x':100,
|
||||||
|
'y':50,
|
||||||
|
'width':200,
|
||||||
|
'height':600,
|
||||||
|
'local_save':false,
|
||||||
|
'get_base64':true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
function InitDevice()
|
function InitDevice()
|
||||||
{
|
{
|
||||||
socket.send(JSON.stringify({
|
socket.send(JSON.stringify({
|
||||||
|
@ -818,6 +844,20 @@
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ImageClip()
|
||||||
|
{
|
||||||
|
socket.send(JSON.stringify({
|
||||||
|
'func':'image_clip',
|
||||||
|
'image_index':0,
|
||||||
|
'x':100,
|
||||||
|
'y':50,
|
||||||
|
'width':200,
|
||||||
|
'height':600,
|
||||||
|
'local_save':false,
|
||||||
|
'get_base64':true
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
window.onload = function()
|
window.onload = function()
|
||||||
{
|
{
|
||||||
var myimg = document.getElementById("myCanvas");
|
var myimg = document.getElementById("myCanvas");
|
||||||
|
@ -863,6 +903,7 @@
|
||||||
<input type="button" value="本地图像添加水印" onclick="LocalImageAddWatermark()" />
|
<input type="button" value="本地图像添加水印" onclick="LocalImageAddWatermark()" />
|
||||||
<input type="button" value="本地图像去污" onclick="LocalImageDecontamination()" />
|
<input type="button" value="本地图像去污" onclick="LocalImageDecontamination()" />
|
||||||
<input type="button" value="本地图像方向校正" onclick="LocalImageDirectCorrect()" />
|
<input type="button" value="本地图像方向校正" onclick="LocalImageDirectCorrect()" />
|
||||||
|
<input type="button" value="本地图像裁剪" onclick="LocalImageClip()" />
|
||||||
|
|
||||||
<input type="button" value="初始化设备" onclick="InitDevice()" />
|
<input type="button" value="初始化设备" onclick="InitDevice()" />
|
||||||
<input type="button" value="反初始化设备" onclick="DeinitDevice()" />
|
<input type="button" value="反初始化设备" onclick="DeinitDevice()" />
|
||||||
|
@ -905,6 +946,7 @@
|
||||||
<input type="button" value="图像添加水印" onclick="ImageAddWatermark()" />
|
<input type="button" value="图像添加水印" onclick="ImageAddWatermark()" />
|
||||||
<input type="button" value="图像去污" onclick="ImageDecontamination()" />
|
<input type="button" value="图像去污" onclick="ImageDecontamination()" />
|
||||||
<input type="button" value="图像方向校正" onclick="ImageDirectCorrect()" />
|
<input type="button" value="图像方向校正" onclick="ImageDirectCorrect()" />
|
||||||
|
<input type="button" value="图像裁剪" onclick="ImageClip()" />
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<img id="myCanvas" width='640' height='480' style="background-color: black; float: left;"/>
|
<img id="myCanvas" width='640' height='480' style="background-color: black; float: left;"/>
|
||||||
|
|
Loading…
Reference in New Issue