63 lines
2.1 KiB
C#
63 lines
2.1 KiB
C#
using Matrox.MatroxImagingLibrary;
|
|
using MilCommon;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Permissions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Interop;
|
|
using VisionCommon;
|
|
|
|
namespace MilPattern
|
|
{
|
|
internal class MilCustomizeMask
|
|
{
|
|
private static MilCustomizeMask _instance;
|
|
private static readonly object _lock = new object();
|
|
private MIL_ID _activatedMilId = MIL.M_NULL;
|
|
private string _activatedFilePath = "";
|
|
|
|
public static MilCustomizeMask Instance {
|
|
get {
|
|
lock (_lock) {
|
|
if (_instance == null) _instance = new MilCustomizeMask();
|
|
}
|
|
return _instance;
|
|
}
|
|
}
|
|
|
|
private MilCustomizeMask() { }
|
|
|
|
public MIL_ID GetActivatedMilId() { return _activatedMilId; }
|
|
public string GetActivatedFilePath() { return _activatedFilePath; }
|
|
public bool IsImageFile(string filePath)
|
|
{
|
|
string[] validExtensions = {".mim", ".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff" };
|
|
string fileExtension = System.IO.Path.GetExtension(filePath).ToLower();
|
|
|
|
foreach (string extension in validExtensions) {
|
|
if (fileExtension == extension) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
public void LoadMaskingImage(string filePath, MIL_ID maskImage)
|
|
{
|
|
if (!IsImageFile(filePath)) return;
|
|
if (_activatedMilId == MIL.M_NULL || _activatedFilePath != filePath) {
|
|
if (_activatedMilId != MIL.M_NULL) MIL.MbufFree(_activatedMilId);
|
|
|
|
_activatedMilId = MilEnvironment.LoadImage(filePath, maskImage);
|
|
_activatedFilePath = filePath;
|
|
}
|
|
}
|
|
public void Mask(MIL_ID srcImage, MIL_ID dstImage)
|
|
{
|
|
if (_activatedFilePath != "" && _activatedMilId != MIL.M_NULL) MIL.MimArith(srcImage, _activatedMilId, dstImage, MIL.M_AND);
|
|
else MilEnvironment.CopyImage(srcImage, dstImage);
|
|
}
|
|
}
|
|
}
|