Ejemplo n.º 1
0
        /// <summary>
        /// Decoding QR code from saved captured image
        /// </summary>
        private void LF_Image_QRCode_Decode(Mat p_image)
        {
            LuminanceSource source;

            source = new BitmapLuminanceSource(BitmapConverter.ToBitmap(p_image));
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            Result       result = new MultiFormatReader().decode(bitmap);

            if (result != null)
            {
                string strDecode = result.ToString() + result.BarcodeFormat.ToString();
                mmeQR.Text += strDecode + "\r\n";
            }
            else
            {
                mmeQR.Text += "False" + "\r\n";
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (this.openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Image  img = Image.FromFile(this.openFileDialog1.FileName);
            Bitmap bmap;

            try
            {
                bmap = new Bitmap(img);
            }
            catch (System.IO.IOException ioe)
            {
                MessageBox.Show(ioe.ToString());
                return;
            }

            if (bmap == null)
            {
                MessageBox.Show("Could not decode image");
                return;
            }

            LuminanceSource source = new RGBLuminanceSource(bmap, bmap.Width, bmap.Height);

            com.google.zxing.BinaryBitmap bitmap = new com.google.zxing.BinaryBitmap(new COMMON.HybridBinarizer(source));
            Result result;

            try
            {
                result = new MultiFormatReader().decode(bitmap);
            }
            catch (ReaderException re)
            {
                MessageBox.Show(re.ToString());
                return;
            }
            textBox1.Text = result.ToString();
            MessageBox.Show(result.Text);
        }
Ejemplo n.º 3
0
        public string ReadQrCode(string base64, string MandateID)
        {
            try
            {
                byte[] data     = Convert.FromBase64String(base64);
                var    filename = MandateID + ".jpg";
                var    path     = "/QRCodeImage/";
                bool   exists   = System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(path));
                if (!exists)
                {
                    System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));
                }
                var file = HttpContext.Current.Server.MapPath(path + filename);
                System.IO.File.WriteAllBytes(file, data);
                path = path + filename;

                Bitmap          bitmap1 = new Bitmap(file);
                int             x = 0, y = 0, width = 1531, height = 486;
                Bitmap          CroppedImage = bitmap1.Clone(new System.Drawing.Rectangle(x, y, width, height), bitmap1.PixelFormat);
                LuminanceSource source;
                source = new BitmapLuminanceSource(CroppedImage);
                BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
                Result       result = new MultiFormatReader().decode(bitmap);

                finalresult = result.ToString();

                bitmap1.Dispose();
                CroppedImage.Dispose();
                System.GC.Collect();
                System.GC.WaitForPendingFinalizers();
                File.Delete(file);
                return(finalresult);
            }
            catch (Exception Ex)
            {
                return(null);
            }
        }
        public GetMandateResponse ReadQrCode(QRImage Data)
        {
            GetMandateResponse response = new GetMandateResponse();

            try
            {
                if (Data.base64Image == "")
                {
                    response.Message = "Incomplete data";
                    response.Status  = "Failure";
                    response.ResCode = "ykR20020";
                    return(response);
                }
                if (Data.base64Image == null)
                {
                    response.Message = "Incomplete data";
                    response.Status  = "Failure";
                    response.ResCode = "ykR20020";
                    return(response);
                }
                if (Data.MandateID == "")
                {
                    response.Message = "Incomplete data";
                    response.Status  = "Failure";
                    response.ResCode = "ykR20020";
                    return(response);
                }
                if (Data.MandateID == null)
                {
                    response.Message = "Incomplete data";
                    response.Status  = "Failure";
                    response.ResCode = "ykR20020";
                    return(response);
                }
                else
                {
                    byte[] data     = Convert.FromBase64String(Data.base64Image);
                    var    filename = Data.MandateID + ".jpg";
                    var    path     = "/QRCodeImage/";
                    bool   exists   = System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(path));

                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));
                    }

                    var file = HttpContext.Current.Server.MapPath(path + filename);
                    System.IO.File.WriteAllBytes(file, data);
                    path = path + filename;

                    Bitmap bitmap1 = new Bitmap(file);
                    //  int x = 0, y = 0, width = 1531, height = 486;
                    int             x = 0, y = 0, width = 260, height = 190;
                    Bitmap          CroppedImage = bitmap1.Clone(new System.Drawing.Rectangle(x + 124, y + 198, width, height), bitmap1.PixelFormat);
                    LuminanceSource source;
                    source = new BitmapLuminanceSource(CroppedImage);
                    // CroppedImage.Save("E:\\abc.jpg");
                    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
                    Result       result = new MultiFormatReader().decode(bitmap);

                    string finalresult = result.ToString();
                    response.Message = finalresult;
                    bitmap1.Dispose();
                    CroppedImage.Dispose();
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                    File.Delete(file);
                    return(response);
                }
            }
            catch (Exception Ex)
            {
                response.Message = "Incomplete data";
                return(response);
            }
        }
        public GetMandateResponseforQRcode ScanQRCode(ScanQRImage Data)
        {
            GetMandateResponseforQRcode response = new GetMandateResponseforQRcode();

            try
            {
                if (Data.AppId == "")
                {
                    response.message = "Incomplete data";
                    response.status  = "Failure";
                    response.ResCode = "ERR000";
                    return(response);
                }
                else if (Data.AppId != "" && CheckMandateInfo.ValidateAppID(Data.AppId) != true)
                {
                    response.message = "Invalid ApplicationId";
                    response.status  = "Failure";
                    response.ResCode = "ykR20023";

                    return(response);
                }
                else if (ValidatePresement.CheckAccess(Data.AppId.Trim(), "A") != true)
                {
                    response.message = "Unauthorized user";
                    response.status  = "Failure";
                    response.ResCode = "ykR20038";
                    return(response);
                }
                else if (Data.EnitityMarchantKey == "")
                {
                    response.message = "Incomplete data";
                    response.status  = "Failure";
                    response.ResCode = "ERR000";
                    return(response);
                }

                else if (Data.EnitityMarchantKey != "" && CheckMandateInfo.ValidateEntityMerchantKey(Data.EnitityMarchantKey, Data.AppId) != true)
                {
                    response.message = "Invalid EnitityMarchantKey";
                    response.status  = "Failure";
                    response.ResCode = "ykR20021";
                    return(response);
                }



                else
                {
                    SqlConnection con  = new SqlConnection(ConfigurationManager.ConnectionStrings[Convert.ToString(Data.AppId)].ConnectionString);
                    bool          Flag = false;
                    //  string temp = ConfigurationManager.AppSettings["EnitityMarchantKey" + Data.AppId];
                    string UserId = "";
                    string query  = "Sp_WebAPI";
                    //if (temp.Trim() == DBsecurity.Decrypt(Data.EnitityMarchantKey))
                    //{
                    SqlCommand cmd = new SqlCommand(query, con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@QueryType", "GetEntityUser");
                    cmd.Parameters.AddWithValue("@appId", Data.AppId);
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataTable      dt = new DataTable();
                    da.Fill(dt);
                    if (dt.Rows.Count > 0)
                    {
                        UserId = Convert.ToString(dt.Rows[0][0]);
                        Flag   = true;
                    }
                    // }


                    if (Flag)
                    {
                        con.Open();
                        query           = "Sp_WebAPI";
                        cmd             = new SqlCommand(query, con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@QueryType", "GetMandateStatus");
                        cmd.Parameters.AddWithValue("@MandateId", Data.MandateID);
                        da = new SqlDataAdapter(cmd);
                        dt = new DataTable();
                        da.Fill(dt);
                        con.Close();
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            response.message       = "Successfully received";
                            response.ResCode       = "KPY000";
                            response.status        = "Success";
                            response.MandateId     = Data.MandateID;
                            response.Mandatestatus = Convert.ToString(dt.Rows[0]["status"]);
                        }
                    }
                }

                if (Data.ScanImage == "")
                {
                    response.message = "Incomplete data";
                    response.status  = "Failure";
                    response.ResCode = "ERR000";
                    return(response);
                }
                if (Data.ScanImage == null)
                {
                    response.message = "Incomplete data";
                    response.status  = "Failure";
                    response.ResCode = "ERR000";
                    return(response);
                }
                if (Data.MandateID == "")
                {
                    response.message = "Incomplete data";
                    response.status  = "Failure";
                    response.ResCode = "ERR000";
                    return(response);
                }
                if (Data.MandateID == null)
                {
                    response.message = "Incomplete data";
                    response.status  = "Failure";
                    response.ResCode = "ERR000";
                    return(response);
                }

                else if (!CheckMandateInfo.CheckManadateID(Data.MandateID, Data.AppId))
                {
                    response.message = "MandateId is not exist";
                    response.status  = "Failure";
                    response.ResCode = "ERR0003";
                    return(response);
                }

                else
                {
                    byte[] data     = Convert.FromBase64String(Data.ScanImage);
                    var    filename = Data.MandateID + ".jpg";
                    var    path     = "/QRCodeImage/";
                    bool   exists   = System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(path));

                    if (!exists)
                    {
                        System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(path));
                    }

                    var file = HttpContext.Current.Server.MapPath(path + filename);
                    System.IO.File.WriteAllBytes(file, data);
                    path = path + filename;

                    Bitmap          bitmap1 = new Bitmap(file);
                    int             x = 0, y = 0, width = 1531, height = 486;
                    Bitmap          CroppedImage = bitmap1.Clone(new System.Drawing.Rectangle(x, y, width, height), bitmap1.PixelFormat);
                    LuminanceSource source;
                    source = new BitmapLuminanceSource(CroppedImage);
                    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
                    Result       result = new MultiFormatReader().decode(bitmap);

                    string finalresult = result.ToString();
                    response.message = finalresult;
                    bitmap1.Dispose();
                    CroppedImage.Dispose();
                    System.GC.Collect();
                    System.GC.WaitForPendingFinalizers();
                    File.Delete(file);
                    return(response);
                }
            }
            catch (Exception Ex)
            {
                response.message = "Incomplete data";
                return(response);
            }
        }