c#将HImage对象保存成图片
将halcon图片对象HImage用C#代码保存到指定目录
/// <summary>
/// 将HImage对象保存成图片
/// </summary>
/// <param name="hImage"></param>
/// <param name="savePath">图像保存目录(注意只是目录)</param>
/// <returns></returns>
public bool SaveImageByHImage(HImage hImage, string savePath = "")
{
var isOk = false;
if (hImage != null)
{
var saveImagePath = "E://test//" + name;
if (!string.IsNullOrEmpty(savePath))
{
saveImagePath = savePath;
}
if (!Directory.Exists(saveImagePath))
{
Directory.CreateDirectory(saveImagePath);
}
saveImagePath= saveImagePath + "//Ng";
if (!Directory.Exists(saveImagePath))
{
Directory.CreateDirectory(saveImagePath);
}
HOperatorSet.WriteImage(hImage, "bmp", 0, saveImagePath + "//" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".bmp");
isOk = true;
}
return isOk;
}