public int ScanKTP(string strfile)
        {
            string strBase64       = string.Empty;
            string directori       = Directory.GetCurrentDirectory();
            string pathsaveimage   = config.Read("PATH", Config.PARAM_PATH_IMAGE_SAVESCANNER);
            string strImageUpFile  = string.Empty;
            string strImageBotFile = string.Empty;

            pathsaveimage = directori + "\\" + pathsaveimage;
            buf           = new byte[6];
            DateTime dateTimeImage         = DateTime.Now;
            string   strImageZhengmianFile = AppDomain.CurrentDomain.BaseDirectory + "idcard_zhengmian.BMP";
            string   strImageBeimianFile   = AppDomain.CurrentDomain.BaseDirectory + "idcard_beimian.BMP";

            if (strfile == "KTP")
            {
                strImageUpFile  = pathsaveimage + "KTP_UP.BMP";
                strImageBotFile = pathsaveimage + "KTP_BOT.BMP";
            }
            else if (strfile == "NPWP")
            {
                strImageUpFile  = pathsaveimage + "NPWP_UP.BMP";
                strImageBotFile = pathsaveimage + "NPWP_BOT.BMP";
            }
            File.Delete(strImageUpFile);
            Utility.WriteLog("ID scanner condition : file from " + strImageUpFile + " has been deleted", "step-action");
            File.Delete(strImageBotFile);
            Utility.WriteLog("ID scanner condition : file from " + strImageBotFile + " has been deleted", "step-action");
            IDCardInfo idCardInfo = new IDCardInfo();

            byte[]           frontPtr = new byte[5242880];
            byte[]           backPtr  = new byte[5242880];
            CrtRect          rect     = new CrtRect();
            IDcardImgOcrInfo ocrInfo  = new IDcardImgOcrInfo();

            res = ScanIDCard(frontPtr, backPtr, strImageUpFile, strImageBotFile, ref rect, ref ocrInfo);
            if (ocrInfo.idNum.Length > 0)
            {
                idCardInfo.ocrValiddate = Encoding.UTF8.GetString(ocrInfo.dateLimit).Replace("\0", "").Replace(" ", "");
            }
            if (ocrInfo.dateLimit.Length > 0)
            {
                idCardInfo.ocrIDnumber = Encoding.UTF8.GetString(ocrInfo.idNum).Replace("\0", "").Replace(" ", "");
            }
            idCardInfo.frontPictureBase64 = ImageHelper.GetBase64FromImage(strImageUpFile);
            idCardInfo.backPictureBase64  = ImageHelper.GetBase64FromImage(strImageBotFile);
            if (strfile == "KTP")
            {
                strBase64 = convertToBase64(strImageUpFile);
                trxbaru.setImageKTP(strBase64);
                Utility.WriteLog("ID scanner condition : set image KTP base64 success", "step-action");
            }
            else if (strfile == "NPWP")
            {
                strBase64 = convertToBase64(strImageUpFile);
                trxbaru.setImageNPWP(strBase64);
                Utility.WriteLog("ID scanner condition : set image NPWP base64 success", "step-action");
            }
            return(res);
        }
        public void Scan()
        {
            string pathsaveimage = config.Read("PATH", Config.PARAM_PATH_IMAGE_SAVESCANNER);

            buf = new byte[6];
            DateTime   dateTimeImage         = DateTime.Now;
            string     strImageZhengmianFile = AppDomain.CurrentDomain.BaseDirectory + "idcard_zhengmian.BMP";
            string     strImageBeimianFile   = AppDomain.CurrentDomain.BaseDirectory + "idcard_beimian.BMP";
            string     strImageUpFile        = pathsaveimage + dateTimeImage.ToString("yyyyMMddHHmm") + "_UP.BMP";
            string     strImageBotFile       = pathsaveimage + dateTimeImage.ToString("yyyyMMddHHmm") + "_BOT.BMP";
            IDCardInfo idCardInfo            = new IDCardInfo();

            byte[]           frontPtr = new byte[5242880];
            byte[]           backPtr  = new byte[5242880];
            CrtRect          rect     = new CrtRect();
            IDcardImgOcrInfo ocrInfo  = new IDcardImgOcrInfo();

            res = ScanIDCard(frontPtr, backPtr, strImageUpFile, strImageBotFile, ref rect, ref ocrInfo);
            if (ocrInfo.idNum.Length > 0)
            {
                idCardInfo.ocrValiddate = Encoding.UTF8.GetString(ocrInfo.dateLimit).Replace("\0", "").Replace(" ", "");
            }
            if (ocrInfo.dateLimit.Length > 0)
            {
                idCardInfo.ocrIDnumber = Encoding.UTF8.GetString(ocrInfo.idNum).Replace("\0", "").Replace(" ", "");
            }
            idCardInfo.frontPictureBase64 = ImageHelper.GetBase64FromImage(strImageUpFile);
            idCardInfo.backPictureBase64  = ImageHelper.GetBase64FromImage(strImageBotFile);

            res = ReturnCard();
            res = CloseCVRReader();
        }
        public int ScanIDCard(byte[] frontPtr, byte[] backPtr, string frontFile, string backFile, ref CrtRect rect, ref IDcardImgOcrInfo idcardImgOcrInfo)
        {
            buf = new byte[6];
            int retCode = ScannerDLL.scan(mDeviceId, 648, 1050, 10);

            if (retCode != 0)
            {
                Utility.WriteLog("ID scanner condition : scanning photo failed", "step-action");
            }
            rect.height = 648;
            rect.width  = 1050;

            retCode = ScannerDLL.readImageDataAndOcr(mDeviceId, frontPtr, backPtr, ref rect, ref idcardImgOcrInfo);
            if (retCode != 0)
            {
                Utility.WriteLog("ID scanner condition : scanning photo failed", "step-action");
                return(retCode = -138);
            }
            retCode = ScannerDLL.saveBmp(frontFile, frontPtr, ref rect);
            if (retCode != 0)
            {
                Utility.WriteLog("ID scanner condition : scanning photo failed", "step-action");
                return(retCode = -138);
            }
            retCode = ScannerDLL.saveBmp(backFile, backPtr, ref rect);
            if (retCode != 0)
            {
                Utility.WriteLog("ID scanner condition : scanning photo failed", "step-action");
                return(retCode = -138);
            }
            Utility.WriteLog("ID scanner condition : scanning photo success", "step-action");
            return(retCode);
        }
 public static extern short readImageDataAndOcr(int devId, byte[] frontPtr, byte[] backPtr, ref CrtRect rect, ref IDcardImgOcrInfo ocrInfo);
 public static extern short readImageData(int devId, byte[] frontPtr, byte[] backPtr, ref CrtRect rect);
 public static extern short saveBmp(string imgFile, byte[] data, ref CrtRect rect);