示例#1
0
        /// <summary>
        /// Method which reads out the first bytes and defines whether the picture, and the text size in the image is ciphered
        /// </summary>
        private void ForRead()
        {
            int    index = (int)Nums.Zero;
            int    ind   = (int)Nums.Zero;
            Bits   bt    = new Bits(255);
            bool   f     = false;
            string str   = null;

            for (var i = (int)Nums.Zero; i < this.im.Width; i++)
            {
                if (f)
                {
                    break;
                }
                for (var j = (int)Nums.Zero; j < this.im.Height; j++)
                {
                    if (index == 8)
                    {
                        index = (int)Nums.Zero;
                        this.lstRead.Add(bt.ToInt());
                        if (Convert.ToChar(this.lstRead[(int)Nums.Zero]) != '*')
                        {
                            MessageBox.Show("In this picture nothing is ciphered!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            f = true;
                            break;
                        }
                        int tmp = (int)Nums.Zero;

                        if (int.TryParse(Convert.ToChar(this.lstRead[ind]).ToString(), out tmp))
                        {
                            if (tmp >= (int)Nums.Zero && tmp <= 9)
                            {
                                tmp  = int.Parse(Convert.ToChar(this.lstRead[ind]).ToString());
                                str += tmp.ToString();
                            }
                        }

                        if (this.lstRead.Count > (int)Nums.One)
                        {
                            if (Convert.ToChar(this.lstRead[ind]) == '*')
                            {
                                f = true;
                                break;
                            }
                        }
                        ind++;
                    }
                    var pixel = this.bm.GetPixel(i, j);

                    Bits r = new Bits(pixel.R);
                    while (r.Lenth != 8)
                    {
                        r.Insert((int)Nums.Zero, (int)Nums.Zero);
                    }
                    bt[index] = r[r.Lenth - (int)Nums.One];
                    r[r.Lenth - (int)Nums.One] = (int)Nums.Zero;

                    this.bm.SetPixel(i, j, Color.FromArgb(r.ToInt(), pixel.G, pixel.B));
                    index++;
                }
            }
            if (str != null)
            {
                this.sizeTxt = int.Parse(str);
            }
        }
示例#2
0
        /// <summary>
        ///  Method in which there is an interpretation of the text from the image
        /// </summary>
        public void ReadFromPictire()
        {
            ind   = (int)Nums.Zero;
            index = (int)Nums.Zero;
            List <int> lst = new List <int>();
            Bits       ar  = new Bits(255);

            this.lstRead = new List <int>();
            bool f = false;

            this.sizeTxt = 0;
            ForRead();
            if (this.sizeTxt == 0)
            {
                f = true;
            }
            ;
            for (var i = (int)Nums.Zero; i < this.im.Width; i++)
            {
                if (f)
                {
                    break;
                }
                for (var j = (int)Nums.Zero; j < this.im.Height; j++)
                {
                    if (j < this.lstRead.Count * 8 && i == 0)
                    {
                        continue;
                    }

                    if ((lst.Count) == this.sizeTxt)
                    {
                        f = true;
                        break;
                    }

                    if (index == 8)
                    {
                        lst.Add(ar.ToInt());
                        ind++;
                        index = (int)Nums.Zero;
                    }

                    var  pixel = this.bm.GetPixel(i, j);
                    Bits r     = new Bits(pixel.R);
                    while (r.Lenth != 8)
                    {
                        r.Insert((int)Nums.Zero, (int)Nums.Zero);
                    }

                    ar[index] = r[r.Lenth - (int)Nums.One];
                    r[r.Lenth - (int)Nums.One] = (int)Nums.Zero;
                    index++;
                    this.bm.SetPixel(i, j, Color.FromArgb(r.ToInt(), pixel.G, pixel.B));
                    if (f)
                    {
                        break;
                    }
                }
            }
            byte[] rezult = new byte[lst.Count];
            ind = (int)Nums.Zero;
            for (var i = (int)Nums.Zero; i < lst.Count; i++)
            {
                rezult[ind] = Convert.ToByte(lst[i]);
                ind++;
            }
            this.name = NewReadName();
            this.bm.Save(this.name);
            this.readTxt = Encoding.GetEncoding(1251).GetString(rezult);
        }