Beispiel #1
0
        public void DrawImage(Chain.Model.Mem mem, string FromUserName)
        {
            Bitmap   smallWeiXin = new Bitmap(130, 130);
            Image    weixinImg   = QRCodeImage.CreateQRCode(mem.MemCard);
            Graphics g           = Graphics.FromImage(smallWeiXin);

            g.DrawImage(weixinImg, new Point(-35, -35));
            string savePath  = this.Server.MapPath("~/Upload/WeiXin/Images/" + FromUserName + ".jpg");
            Bitmap bigWeiXin = new Bitmap(200, 200);

            g = Graphics.FromImage(bigWeiXin);
            g.DrawImage(smallWeiXin, new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 130, 130), GraphicsUnit.Pixel);
            string bg    = this.Server.MapPath("~/Upload/WeiXin/Images/bg.jpg");
            Image  bgImg = Image.FromFile(bg, true);
            Bitmap bmp   = new Bitmap(bgImg.Width, bgImg.Height, PixelFormat.Format32bppArgb);

            g = Graphics.FromImage(bmp);
            g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            g.CompositingQuality = CompositingQuality.HighQuality;
            g.DrawImage(bgImg, new Rectangle(0, 0, bgImg.Width, bgImg.Height), new Rectangle(0, 0, bgImg.Width, bgImg.Height), GraphicsUnit.Pixel);
            g.DrawImage(bigWeiXin, new RectangleF(50f, 60f, 200f, 200f), new RectangleF(0f, 0f, 200f, 200f), GraphicsUnit.Pixel);
            g.DrawString("NO:" + mem.MemCard, new Font("微软雅黑", 34f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 70f));
            g.DrawString("积分:" + mem.MemCard, new Font("微软雅黑", 30f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 115f));
            g.DrawString("余额:" + mem.MemMoney.ToString("F2"), new Font("微软雅黑", 30f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 160f));
            string pastStr = (mem.MemPastTime.ToString("yyyy-MM-dd") == "2900-01-01") ? "有效期:永久有效" : ("有效期:" + mem.MemPastTime.ToString("yyyy-MM-dd"));

            g.DrawString(pastStr, new Font("微软雅黑", 30f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 205f));
            bmp.Save(savePath, ImageFormat.Jpeg);
        }
Beispiel #2
0
 public virtual string decode(QRCodeImage qrCodeImage)
 {
     sbyte[] numArray = this.decodeBytes(qrCodeImage);
     byte[]  bytes    = new byte[numArray.Length];
     Buffer.BlockCopy((Array)numArray, 0, (Array)bytes, 0, bytes.Length);
     return(Encoding.GetEncoding("gb2312").GetString(bytes));
 }
Beispiel #3
0
 public virtual string decode(QRCodeImage qrCodeImage, Encoding encoding)
 {
     sbyte[] src = this.decodeBytes(qrCodeImage);
     byte[]  dst = new byte[src.Length];
     Buffer.BlockCopy(src, 0, dst, 0, dst.Length);
     return(encoding.GetString(dst));
 }
 public virtual string decode(QRCodeImage qrCodeImage)
 {
     sbyte[] numArray1 = this.decodeBytes(qrCodeImage);
     byte[]  numArray2 = new byte[numArray1.Length];
     Buffer.BlockCopy((Array)numArray1, 0, (Array)numArray2, 0, numArray2.Length);
     return((!QRCodeUtility.IsUnicode(numArray2) ? Encoding.ASCII : Encoding.Unicode).GetString(numArray2));
 }
Beispiel #5
0
        public bool UpdateQRCode(QRCodeImage image, string ID)
        {
            int _id = Convert.ToInt32(ID);

            using (EventrixDBDataContext db = new EventrixDBDataContext())
            {
                var query = (from img in db.Guest_QRCodes
                             where img.QR_Id.Equals(_id)
                             select img);
                if (query.Count() != 0)
                {
                    Guest_QRCode toinsert = query.Single();
                    toinsert.Name     = image.Name;
                    toinsert.Location = image.Location;

                    //    db.EventViews.InsertOnSubmit(toinsert);
                    db.SubmitChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            };
        }
Beispiel #6
0
 public virtual string decode(QRCodeImage qrCodeImage, Encoding encoding)
 {
     sbyte[] array  = decodeBytes(qrCodeImage);
     byte[]  array2 = new byte[array.Length];
     Buffer.BlockCopy(array, 0, array2, 0, array2.Length);
     return(encoding.GetString(array2));
 }
Beispiel #7
0
 public virtual string decode(QRCodeImage qrCodeImage)
 {
     sbyte[] src = this.decodeBytes(qrCodeImage);
     byte[] dst = new byte[src.Length];
     Buffer.BlockCopy(src, 0, dst, 0, dst.Length);
     return Encoding.GetEncoding("gb2312").GetString(dst);
 }
Beispiel #8
0
        private void cmd_Click(object sender, EventArgs e)
        {
            try
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();

                //Creation de l'image QRCode
                Image img = QRCodeImage.GetGenerateQRCode(txt.Text, "L", "", 0);//L, M ou Q

                pbox.Image = img;

                //Conversion de l'image se trouvant dans le PictureBox pour le convertir en Base64

                string fileName = clsTools.Instance.SaveTempImage(pbox);
                //Chaine string
                txtText.Text = clsTools.Instance.GetByteFromFile(fileName).ToString();

                //Tableau Bytes
                //lstImg.DataSource = outils.PictureBoxImageToBytes(outils.getImageFromByte(fileName));

                clsTools.Instance.RemoveTempImage(fileName);

                sw.Stop();
                MessageBox.Show("Complete in " + (sw.ElapsedMilliseconds / 1000) + "Sec");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur lors de la création et conversion + " + ex.Message, "Création et Conversion QRCode en texte", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
            }
        }
Beispiel #9
0
        public void DrawImage(Chain.Model.Mem mem, string FromUserName)
        {
            Bitmap   smallWeiXin = new Bitmap(130, 130);
            Image    weixinImg   = QRCodeImage.CreateQRCode(mem.MemCard);
            Graphics g           = Graphics.FromImage(smallWeiXin);

            g.DrawImage(weixinImg, new Point(-35, -35));
            string savePath  = base.Server.MapPath("~/Upload/WeiXin/Images/" + FromUserName + ".jpg");
            Bitmap bigWeiXin = new Bitmap(200, 200);

            g = Graphics.FromImage(bigWeiXin);
            g.DrawImage(smallWeiXin, new Rectangle(0, 0, 200, 200), new Rectangle(0, 0, 130, 130), GraphicsUnit.Pixel);
            string bg     = base.Server.MapPath("~/Upload/WeiXin/Images/bg.jpg");
            Bitmap result = new Bitmap(bg);

            g = Graphics.FromImage(result);
            g.DrawImage(bigWeiXin, new RectangleF(50f, 60f, 200f, 200f), new RectangleF(0f, 0f, 200f, 200f), GraphicsUnit.Pixel);
            g.DrawString("NO:" + mem.MemCard, new Font("微软雅黑", 34f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 70f));
            g.DrawString("积分:" + mem.MemCard, new Font("微软雅黑", 30f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 115f));
            g.DrawString("余额:" + mem.MemMoney.ToString("F2"), new Font("微软雅黑", 30f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 160f));
            string pastStr = (mem.MemPastTime.ToString("yyyy-MM-dd") == "2900-01-01") ? "有效期:永久有效" : ("有效期:" + mem.MemPastTime.ToString("yyyy-MM-dd"));

            g.DrawString(pastStr, new Font("微软雅黑", 30f, FontStyle.Regular, GraphicsUnit.Pixel), Brushes.White, new PointF(280f, 205f));
            result.Save(savePath, ImageFormat.Jpeg);
        }
Beispiel #10
0
 public virtual string decode(QRCodeImage qrCodeImage, Encoding encoding)
 {
     sbyte[] data     = this.decodeBytes(qrCodeImage);
     byte[]  byteData = new byte[data.Length];
     Buffer.BlockCopy(data, 0, byteData, 0, byteData.Length);
     return(encoding.GetString(byteData));
 }
Beispiel #11
0
        public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage)
        {
            DecodeResult result;

            Point[]   adjustPoints = this.AdjustPoints;
            ArrayList list         = ArrayList.Synchronized(new ArrayList(10));

            while (this.numTryDecode < adjustPoints.Length)
            {
                try
                {
                    try
                    {
                        result = this.decode(qrCodeImage, adjustPoints[this.numTryDecode]);
                        if (result.CorrectionSucceeded)
                        {
                            return(result.DecodedBytes);
                        }
                        list.Add(result);
                        canvas.println("Decoding succeeded but could not correct");
                        canvas.println("all errors. Retrying..");
                    }
                    catch (DecodingFailedException exception)
                    {
                        if (exception.Message.IndexOf("Finder Pattern") >= 0)
                        {
                            throw exception;
                        }
                    }
                    continue;
                }
                finally
                {
                    this.numTryDecode++;
                }
            }
            if (list.Count == 0)
            {
                throw new DecodingFailedException("Give up decoding");
            }
            int num       = -1;
            int numErrors = 0x7fffffff;

            for (int i = 0; i < list.Count; i++)
            {
                result = (DecodeResult)list[i];
                if (result.NumErrors < numErrors)
                {
                    numErrors = result.NumErrors;
                    num       = i;
                }
            }
            canvas.println("All trials need for correct error");
            canvas.println("Reporting #" + num + " that,");
            canvas.println("corrected minimum errors (" + numErrors + ")");
            canvas.println("Decoding finished.");
            return(((DecodeResult)list[num]).DecodedBytes);
        }
Beispiel #12
0
        public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage)
        {
            Point[] adjusts = AdjustPoints;
            System.Collections.ArrayList results = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            while (numTryDecode < adjusts.Length)
            {
                try
                {
                    DecodeResult result = decode(qrCodeImage, adjusts[numTryDecode]);
                    if (result.CorrectionSucceeded)
                    {
                        return(result.DecodedBytes);
                    }
                    else
                    {
                        results.Add(result);
                        canvas.println("Decoding succeeded but could not correct");
                        canvas.println("all errors. Retrying..");
                    }
                }
                catch (DecodingFailedException dfe)
                {
                    if (dfe.Message.IndexOf("Finder Pattern") >= 0)
                    {
                        throw dfe;
                    }
                }
                finally
                {
                    numTryDecode += 1;
                }
            }

            if (results.Count == 0)
            {
                throw new DecodingFailedException("Give up decoding");
            }

            int lowestErrorIndex = -1;
            int lowestError      = System.Int32.MaxValue;

            for (int i = 0; i < results.Count; i++)
            {
                DecodeResult result = (DecodeResult)results[i];
                if (result.NumErrors < lowestError)
                {
                    lowestError      = result.NumErrors;
                    lowestErrorIndex = i;
                }
            }
            canvas.println("All trials need for correct error");
            canvas.println("Reporting #" + (lowestErrorIndex) + " that,");
            canvas.println("corrected minimum errors (" + lowestError + ")");

            canvas.println("Decoding finished.");
            return(((DecodeResult)results[lowestErrorIndex]).DecodedBytes);
        }
Beispiel #13
0
        public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage)
        {
            Point[]   adjusts = this.AdjustPoints;
            ArrayList results = ArrayList.Synchronized(new ArrayList(10));

            sbyte[] decodedBytes;
            while (this.numTryDecode < adjusts.Length)
            {
                try
                {
                    QRCodeDecoder.DecodeResult result = this.decode(qrCodeImage, adjusts[this.numTryDecode]);
                    if (result.CorrectionSucceeded)
                    {
                        decodedBytes = result.DecodedBytes;
                        return(decodedBytes);
                    }
                    results.Add(result);
                    QRCodeDecoder.canvas.println("Decoding succeeded but could not correct");
                    QRCodeDecoder.canvas.println("all errors. Retrying..");
                }
                catch (DecodingFailedException dfe)
                {
                    if (dfe.Message.IndexOf("Finder Pattern") >= 0)
                    {
                        throw dfe;
                    }
                }
                finally
                {
                    this.numTryDecode++;
                }
            }
            if (results.Count == 0)
            {
                throw new DecodingFailedException("Give up decoding");
            }
            int lowestErrorIndex = -1;
            int lowestError      = 2147483647;

            for (int i = 0; i < results.Count; i++)
            {
                QRCodeDecoder.DecodeResult result = (QRCodeDecoder.DecodeResult)results[i];
                if (result.NumErrors < lowestError)
                {
                    lowestError      = result.NumErrors;
                    lowestErrorIndex = i;
                }
            }
            QRCodeDecoder.canvas.println("All trials need for correct error");
            QRCodeDecoder.canvas.println("Reporting #" + lowestErrorIndex + " that,");
            QRCodeDecoder.canvas.println("corrected minimum errors (" + lowestError + ")");
            QRCodeDecoder.canvas.println("Decoding finished.");
            decodedBytes = ((QRCodeDecoder.DecodeResult)results[lowestErrorIndex]).DecodedBytes;
            return(decodedBytes);
        }
Beispiel #14
0
    private void ShowLoginQRCode()
    {
        if (!QRCodeGO.activeSelf)
        {
            Debug.Log("Show");
            QRCodeImage qRCodeImage = QRCodeGO.GetComponent <QRCodeImage>();
            StartCoroutine(qRCodeImage.Show());
            //qRCodeImage.Show();
        }

        Debug.Log("Hello");
    }
        /// <summary>
        /// The decode.
        /// </summary>
        /// <param name="qrCodeImage">
        /// The qr code image.
        /// </param>
        /// <returns>
        /// The decode.
        /// </returns>
        public virtual string decode(QRCodeImage qrCodeImage)
        {
            sbyte[] data     = this.decodeBytes(qrCodeImage);
            byte[]  byteData = new byte[data.Length];
            Buffer.BlockCopy(data, 0, byteData, 0, byteData.Length);

            Encoding encoding = QRCodeUtility.IsUnicode(byteData) ? Encoding.Unicode : Encoding.ASCII;

            string decodedData = encoding.GetString(byteData);

            return(decodedData);
        }
Beispiel #16
0
        public virtual sbyte[] DecodeBytes(QRCodeImage qrCodeImage)
        {
            Point[]   adjustPoints = this.AdjustPoints;
            ArrayList arrayList    = ArrayList.Synchronized(new ArrayList(10));

            this.numTryDecode = 0;
            while (this.numTryDecode < adjustPoints.Length)
            {
                try
                {
                    QRCodeDecoder.DecodeResult decodeResult = this.Decode(qrCodeImage, adjustPoints[this.numTryDecode]);
                    if (decodeResult.IsCorrectionSucceeded)
                    {
                        return(decodeResult.DecodedBytes);
                    }
                    arrayList.Add((object)decodeResult);
                    QRCodeDecoder.canvas.Print("Decoding succeeded but could not correct");
                    QRCodeDecoder.canvas.Print("all errors. Retrying..");
                }
                catch (DecodingFailedException ex)
                {
                    if (ex.Message.IndexOf("Finder Pattern") >= 0)
                    {
                        throw ex;
                    }
                }
                finally
                {
                    ++this.numTryDecode;
                }
            }
            if (arrayList.Count == 0)
            {
                throw new DecodingFailedException("Give up decoding");
            }
            int index1 = -1;
            int num    = int.MaxValue;

            for (int index2 = 0; index2 < arrayList.Count; ++index2)
            {
                QRCodeDecoder.DecodeResult decodeResult = (QRCodeDecoder.DecodeResult)arrayList[index2];
                if (decodeResult.NumCorrectionFailures < num)
                {
                    num    = decodeResult.NumCorrectionFailures;
                    index1 = index2;
                }
            }
            QRCodeDecoder.canvas.Print("All trials need for correct error");
            QRCodeDecoder.canvas.Print("Reporting #" + (object)index1 + " that,");
            QRCodeDecoder.canvas.Print("corrected minimum errors (" + (object)num + ")");
            QRCodeDecoder.canvas.Print("Decoding finished.");
            return(((QRCodeDecoder.DecodeResult)arrayList[index1]).DecodedBytes);
        }
Beispiel #17
0
        public static string SendMMSToWG(string id, string pwd, string Mobile, string Subject, string Content)
        {
            string result   = "";
            string subject  = HexConvert.StringToHexString(Subject, SendMessage.encode);
            string d        = Convert.ToString(1);
            string tt       = "txt";
            string file     = HttpContext.Current.Server.MapPath("");
            string tv       = HexConvert.GetHexString(HexConvert.FileToBytes(file + "\\Readme.txt"));
            string pt       = "jpg";
            string pv       = HexConvert.GetHexString(QRCodeImage.imageToByte(Content));
            string url      = "http://118.144.76.79:8080/mmsServer/sendMms";
            string postdata = string.Concat(new string[]
            {
                "id=",
                id,
                "&pwd=",
                pwd,
                "&subject=",
                subject,
                "&d1=",
                d,
                "&tt1=",
                tt,
                "&tv1=",
                tv,
                "&pt1=",
                pt,
                "&pv1=",
                pv,
                "&mt1=&mv1="
            });
            string mms_id = SendMessage.PostSend(url, postdata);

            if (mms_id != null & int.Parse(mms_id) > 0)
            {
                url      = "http://118.144.76.79:8080/mmsServer/sendMobile";
                postdata = string.Concat(new string[]
                {
                    "id=",
                    id,
                    "&pwd=",
                    pwd,
                    "&yw=10690029yd&mobile=",
                    Mobile,
                    "&mms_id=",
                    mms_id
                });
                result = SendMessage.PostSend(url, postdata);
            }
            return(result);
        }
        private QRCodeImage GenerateCode(EventTicket _ticket, int count, string G_ID, int bridgingID, string EventID)
        {
            string ImageName = "Dummy";
            //store New image to database
            QRCodeImage img    = new QRCodeImage();
            QRCodeImage qrcode = new QRCodeImage();

            img.Name         = ImageName;
            img.ticket_ID    = bridgingID;
            img.EntranceTime = DateTime.Now;
            img.Checked_in   = 0;
            img.Credit       = _ticket._Credit;
            img.Location     = "Dummy";
            FileUploadClient fuc = new FileUploadClient();
            int intQRCodeID      = fuc.saveQRCodeImage(img);

            if (intQRCodeID != 0)
            {
                //create QR Code Image
                string QRCodeCotntent = Convert.ToString(intQRCodeID);
                var    writer         = new BarcodeWriter();
                writer.Format = BarcodeFormat.QR_CODE; //populate code with GuestID
                var    result = writer.Write(QRCodeCotntent);
                string path   = Server.MapPath("~/Events/" + _ticket._EventID + "/QR_Codes/" + bridgingID + "_" + G_ID + "_QRImage.jpg");
                ImageName = bridgingID + "_" + G_ID + "_QRImage.jpg";
                var barcodeBitmap = new Bitmap(result);
                using (MemoryStream memory = new MemoryStream())
                {
                    using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite))
                    {
                        barcodeBitmap.Save(memory, ImageFormat.Png);
                        byte[] bytes = memory.ToArray();
                        fs.Write(bytes, 0, bytes.Length);
                    }
                }

                //UPdate Last Added QRCode Image
                qrcode.Name         = ImageName;
                qrcode.Location     = path;
                qrcode.EntranceTime = DateTime.Now;

                bool isUpdated = fuc.UpdateQRCode(qrcode, Convert.ToString(intQRCodeID));
                if (isUpdated == true)
                {
                    //Alert is created
                }
            }
            return(qrcode);
        }
 //Insertions
 //saveQRCodeImage
 public int saveQRCodeImage(QRCodeImage image)
 {
     string response = null;
     string data = null;
         DataContractJsonSerializer ser = new DataContractJsonSerializer(
             typeof(QRCodeImage));
         MemoryStream mem = new MemoryStream();
         ser.WriteObject(mem, image);
         data = Encoding.UTF8.GetString(mem.ToArray(), 0, (int)mem.Length);
         WebClient webClient = new WebClient();
         webClient.Headers["Content-type"] = "application/json";
         webClient.Encoding = Encoding.UTF8;
         response = webClient.UploadString(BASE_URL + "saveQRCodeImage", "POST", data);
     int ID = Convert.ToInt32(response);
         return ID;
 }
Beispiel #20
0
 //scanning QR Code and changing the check in status
 public bool updateQRCode(QRCodeImage image)
 {
     try
     {
         using (EventrixDBDataContext db = new EventrixDBDataContext())
         {
             Guest_QRCode toInsert = (from st in db.Guest_QRCodes where st.QR_Id.Equals(image.QRCodeID) select st).First();
             toInsert.Checked_In = image.Checked_in;
             db.SubmitChanges();
             return(true);
         };
     }catch (Exception)
     {
         return(false);
     }
 }
        private void QRCodeTimer_Tick(object sender, EventArgs e)
        {
            QRCodeTimer.Enabled = false;
            Bitmap QRCodeImage;

            try
            {
                QRCodeImage = VideoCamera.SnapshotSourceImage();

                // trace
                        #if DEBUG
                QRCodeTrace.Format("Image width: {0}, Height: {1}", QRCodeImage.Width, QRCodeImage.Height);
                        #endif
            }

            catch (Exception EX)
            {
                DataTextBox.Text    = "Decode exception.\r\n" + EX.Message;
                QRCodeTimer.Enabled = true;
                return;
            }

            // decode image
            byte[][] DataByteArray = Decoder.ImageDecoder(QRCodeImage);
            string   Text          = QRCodeResult(DataByteArray);

            // dispose bitmap
            QRCodeImage.Dispose();

            // we have no QR code
            if (Text.Length == 0)
            {
                QRCodeTimer.Enabled = true;
                return;
            }

            VideoCamera.PauseGraph();

            DataTextBox.Text    = Text;
            ResetButton.Enabled = true;
            if (IsValidUri(DataTextBox.Text))
            {
                GoToUriButton.Enabled = true;
            }
            return;
        }
Beispiel #22
0
        public virtual string decode(QRCodeImage qrCodeImage)
        {
            Encoding aSCII;

            sbyte[] src = this.decodeBytes(qrCodeImage);
            byte[]  dst = new byte[src.Length];
            Buffer.BlockCopy(src, 0, dst, 0, dst.Length);
            if (QRCodeUtility.IsUnicode(dst))
            {
                aSCII = Encoding.GetEncoding("gb2312");
            }
            else
            {
                aSCII = Encoding.ASCII;
            }
            return(aSCII.GetString(dst));
        }
        /// <summary>
        /// The decode.
        /// </summary>
        /// <param name="qrCodeImage">
        /// The qr code image.
        /// </param>
        /// <param name="adjust">
        /// The adjust.
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="DecodingFailedException">
        /// </exception>
        /// <exception cref="DecodingFailedException">
        /// </exception>
        internal virtual DecodeResult decode(QRCodeImage qrCodeImage, Point adjust)
        {
            try
            {
                if (this.numTryDecode == 0)
                {
                    canvas.println("Decoding started");
                    int[][] intImage = this.imageToIntArray(qrCodeImage);
                    this.imageReader  = new QRCodeImageReader();
                    this.qrCodeSymbol = this.imageReader.getQRCodeSymbol(intImage);
                }
                else
                {
                    canvas.println("--");
                    canvas.println("Decoding restarted #" + this.numTryDecode);
                    this.qrCodeSymbol = this.imageReader.getQRCodeSymbolWithAdjustedGrid(adjust);
                }
            }
            catch (SymbolNotFoundException e)
            {
                throw new DecodingFailedException(e.Message);
            }

            canvas.println("Created QRCode symbol.");
            canvas.println("Reading symbol.");
            canvas.println("Version: " + this.qrCodeSymbol.VersionReference);
            canvas.println("Mask pattern: " + this.qrCodeSymbol.MaskPatternRefererAsString);

            // blocks contains all (data and RS) blocks in QR Code symbol
            int[] blocks = this.qrCodeSymbol.Blocks;
            canvas.println("Correcting data errors.");

            // now blocks turn to data blocks (corrected and extracted from original blocks)
            blocks = this.correctDataBlocks(blocks);
            try
            {
                sbyte[] decodedByteArray = this.getDecodedByteArray(
                    blocks, this.qrCodeSymbol.Version, this.qrCodeSymbol.NumErrorCollectionCode);
                return(new DecodeResult(this, decodedByteArray, this.numLastCorrections, this.correctionSucceeded));
            }
            catch (InvalidDataBlockException e)
            {
                canvas.println(e.Message);
                throw new DecodingFailedException(e.Message);
            }
        }
Beispiel #24
0
        internal virtual int[][] imageToIntArray(QRCodeImage image)
        {
            int width  = image.Width;
            int height = image.Height;

            int[][] numArray = new int[width][];
            for (int index = 0; index < width; ++index)
            {
                numArray[index] = new int[height];
            }
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    numArray[x][y] = image.getPixel(x, y);
                }
            }
            return(numArray);
        }
Beispiel #25
0
        internal virtual DecodeResult decode(QRCodeImage qrCodeImage, Point adjust)
        {
            DecodeResult result;

            try
            {
                if (this.numTryDecode == 0)
                {
                    canvas.println("Decoding started");
                    int[][] image = this.imageToIntArray(qrCodeImage);
                    this.imageReader  = new QRCodeImageReader();
                    this.qrCodeSymbol = this.imageReader.getQRCodeSymbol(image);
                }
                else
                {
                    canvas.println("--");
                    canvas.println("Decoding restarted #" + this.numTryDecode);
                    this.qrCodeSymbol = this.imageReader.getQRCodeSymbolWithAdjustedGrid(adjust);
                }
            }
            catch (SymbolNotFoundException exception)
            {
                throw new DecodingFailedException(exception.Message);
            }
            canvas.println("Created QRCode symbol.");
            canvas.println("Reading symbol.");
            canvas.println("Version: " + this.qrCodeSymbol.VersionReference);
            canvas.println("Mask pattern: " + this.qrCodeSymbol.MaskPatternRefererAsString);
            int[] blocks = this.qrCodeSymbol.Blocks;
            canvas.println("Correcting data errors.");
            blocks = this.correctDataBlocks(blocks);
            try
            {
                sbyte[] decodedBytes = this.getDecodedByteArray(blocks, this.qrCodeSymbol.Version, this.qrCodeSymbol.NumErrorCollectionCode);
                result = new DecodeResult(this, decodedBytes, this.numLastCorrections, this.correctionSucceeded);
            }
            catch (InvalidDataBlockException exception2)
            {
                canvas.println(exception2.Message);
                throw new DecodingFailedException(exception2.Message);
            }
            return(result);
        }
Beispiel #26
0
        internal virtual int[][] imageToIntArray(QRCodeImage image)
        {
            int width  = image.Width;
            int height = image.Height;

            int[][] array = new int[width][];
            for (int i = 0; i < width; i++)
            {
                array[i] = new int[height];
            }
            for (int j = 0; j < height; j++)
            {
                for (int k = 0; k < width; k++)
                {
                    array[k][j] = image.getPixel(k, j);
                }
            }
            return(array);
        }
Beispiel #27
0
        internal virtual int[][] imageToIntArray(QRCodeImage image)
        {
            int width  = image.Width;
            int height = image.Height;

            int[][] intImage = new int[width][];
            for (int i = 0; i < width; i++)
            {
                intImage[i] = new int[height];
            }
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    intImage[x][y] = image.GetPixel(x, y);
                }
            }
            return(intImage);
        }
        /// <summary>
        /// The decode.
        /// </summary>
        /// <param name="qrCodeImage">
        /// The qr code image.
        /// </param>
        /// <param name="encoding">
        /// The encoding.
        /// </param>
        /// <returns>
        /// The decode.
        /// </returns>
        public virtual string decode(QRCodeImage qrCodeImage, Encoding encoding)
        {
            sbyte[] data     = this.decodeBytes(qrCodeImage);
            byte[]  byteData = new byte[data.Length];

            Buffer.BlockCopy(data, 0, byteData, 0, byteData.Length);

            /*
             * char[] decodedData = new char[data.Length];
             * for (int i = 0; i < data.Length; i++)
             * {
             *  decodedData[i] = Convert.to(data[i]);
             *
             * }
             * return new String(decodedData);
             */
            string decodedData = encoding.GetString(byteData);

            return(decodedData);
        }
Beispiel #29
0
        public virtual string decode(QRCodeImage qrCodeImage)
        {
            sbyte[] data     = decodeBytes(qrCodeImage);
            byte[]  byteData = new byte[data.Length];
            Buffer.BlockCopy(data, 0, byteData, 0, byteData.Length);

            Encoding encoding;

            if (QRCodeUtility.IsUnicode(byteData))
            {
                encoding = Encoding.Unicode;
            }
            else
            {
                encoding = Encoding.ASCII;
            }
            string decodedData;

            decodedData = encoding.GetString(byteData);
            return(decodedData);
        }
Beispiel #30
0
 internal virtual QRCodeDecoder.DecodeResult Decode(QRCodeImage qrCodeImage, Point adjust)
 {
     try
     {
         if (this.numTryDecode == 0)
         {
             QRCodeDecoder.canvas.Print("Decoding started");
             int[][] intArray = this.imageToIntArray(qrCodeImage);
             this.imageReader  = new QRCodeImageReader();
             this.qrCodeSymbol = this.imageReader.GetQRCodeSymbol(intArray);
         }
         else
         {
             QRCodeDecoder.canvas.Print("--");
             QRCodeDecoder.canvas.Print("Decoding restarted #" + (object)this.numTryDecode);
             this.qrCodeSymbol = this.imageReader.GetQRCodeSymbolWithAdjustedGrid(adjust);
         }
     }
     catch (SymbolNotFoundException ex)
     {
         throw new DecodingFailedException(ex.Message);
     }
     QRCodeDecoder.canvas.Print("Created QRCode symbol.");
     QRCodeDecoder.canvas.Print("Reading symbol.");
     QRCodeDecoder.canvas.Print("Version: " + this.qrCodeSymbol.VersionReference);
     QRCodeDecoder.canvas.Print("Mask pattern: " + this.qrCodeSymbol.MaskPatternRefererAsString);
     int[] blocks1 = this.qrCodeSymbol.Blocks;
     QRCodeDecoder.canvas.Print("Correcting data errors.");
     int[] blocks2 = this.CorrectDataBlocks(blocks1);
     try
     {
         return(new QRCodeDecoder.DecodeResult(this, this.GetDecodedByteArray(blocks2, this.qrCodeSymbol.Version, this.qrCodeSymbol.NumErrorCollectionCode), this.numLastCorrectionFailures));
     }
     catch (InvalidDataBlockException ex)
     {
         QRCodeDecoder.canvas.Print(ex.Message);
         throw new DecodingFailedException(ex.Message);
     }
 }
Beispiel #31
0
 public int saveQRCodeImage(QRCodeImage imageUp)
 {
     try
     {
         Guest_QRCode fileToSave = new Guest_QRCode();
         using (EventrixDBDataContext db = new EventrixDBDataContext())
         {
             var query = from image in db.Guest_QRCodes where image.QR_Id.Equals(imageUp.QRCodeID) select image;
             if (query.Count() == 0)
             {
                 fileToSave.Name         = imageUp.Name;
                 fileToSave.ticket_Id    = imageUp.ticket_ID;
                 fileToSave.Location     = imageUp.Location;
                 fileToSave.EntranceTime = imageUp.EntranceTime;
                 fileToSave.Checked_In   = 0;
                 fileToSave.Credit       = imageUp.Credit;
                 // fileToSave.tick = Convert.ToInt32(imageUp.EventID);
                 db.Guest_QRCodes.InsertOnSubmit(fileToSave);
                 db.SubmitChanges();
             }
             else
             if (query.Count() == 1)
             {
                 return(0);
             }
         };
         using (EventrixDBDataContext db = new EventrixDBDataContext())
         {
             var          query = (from tk in db.Guest_QRCodes select tk).ToList();
             Guest_QRCode tick  = query.Last();
             int          ID    = tick.QR_Id;
             return(ID);
         };
     }
     catch (Exception)
     {
         return(0);
     }
 }
Beispiel #32
0
 internal virtual DecodeResult decode(QRCodeImage qrCodeImage, Point adjust)
 {
     DecodeResult result;
     try
     {
         if (this.numTryDecode == 0)
         {
             canvas.println("Decoding started");
             int[][] image = this.imageToIntArray(qrCodeImage);
             this.imageReader = new QRCodeImageReader();
             this.qrCodeSymbol = this.imageReader.getQRCodeSymbol(image);
         }
         else
         {
             canvas.println("--");
             canvas.println("Decoding restarted #" + this.numTryDecode);
             this.qrCodeSymbol = this.imageReader.getQRCodeSymbolWithAdjustedGrid(adjust);
         }
     }
     catch (SymbolNotFoundException exception)
     {
         throw new DecodingFailedException(exception.Message);
     }
     canvas.println("Created QRCode symbol.");
     canvas.println("Reading symbol.");
     canvas.println("Version: " + this.qrCodeSymbol.VersionReference);
     canvas.println("Mask pattern: " + this.qrCodeSymbol.MaskPatternRefererAsString);
     int[] blocks = this.qrCodeSymbol.Blocks;
     canvas.println("Correcting data errors.");
     blocks = this.correctDataBlocks(blocks);
     try
     {
         sbyte[] decodedBytes = this.getDecodedByteArray(blocks, this.qrCodeSymbol.Version, this.qrCodeSymbol.NumErrorCollectionCode);
         result = new DecodeResult(this, decodedBytes, this.numLastCorrections, this.correctionSucceeded);
     }
     catch (InvalidDataBlockException exception2)
     {
         canvas.println(exception2.Message);
         throw new DecodingFailedException(exception2.Message);
     }
     return result;
 }
Beispiel #33
0
 internal virtual int[][] imageToIntArray(QRCodeImage image)
 {
     int width = image.Width;
     int height = image.Height;
     int[][] numArray = new int[width][];
     for (int i = 0; i < width; i++)
     {
         numArray[i] = new int[height];
     }
     for (int j = 0; j < height; j++)
     {
         for (int k = 0; k < width; k++)
         {
             numArray[k][j] = image.getPixel(k, j);
         }
     }
     return numArray;
 }
Beispiel #34
0
 public virtual sbyte[] decodeBytes(QRCodeImage qrCodeImage)
 {
     DecodeResult result;
     Point[] adjustPoints = this.AdjustPoints;
     ArrayList list = ArrayList.Synchronized(new ArrayList(10));
     while (this.numTryDecode < adjustPoints.Length)
     {
         try
         {
             result = this.decode(qrCodeImage, adjustPoints[this.numTryDecode]);
             if (result.CorrectionSucceeded)
             {
                 return result.DecodedBytes;
             }
             list.Add(result);
             canvas.println("Decoding succeeded but could not correct");
             canvas.println("all errors. Retrying..");
         }
         catch (DecodingFailedException exception)
         {
             if (exception.Message.IndexOf("Finder Pattern") >= 0)
             {
                 throw exception;
             }
         }
         finally
         {
             this.numTryDecode++;
         }
     }
     if (list.Count == 0)
     {
         throw new DecodingFailedException("Give up decoding");
     }
     int num = -1;
     int numErrors = 0x7fffffff;
     for (int i = 0; i < list.Count; i++)
     {
         result = (DecodeResult) list[i];
         if (result.NumErrors < numErrors)
         {
             numErrors = result.NumErrors;
             num = i;
         }
     }
     canvas.println("All trials need for correct error");
     canvas.println("Reporting #" + num + " that,");
     canvas.println("corrected minimum errors (" + numErrors + ")");
     canvas.println("Decoding finished.");
     return ((DecodeResult) list[num]).DecodedBytes;
 }