示例#1
0
文件: Form1.cs 项目: ohegba/NewLeafQR
        private void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Hi");

            if (!Clipboard.ContainsImage())
            {
                MessageBox.Show("No image on the clipboard!");
                return;
            }
            MemoryStream fs;


            fs = QRFromClipboard();



            BinaryReader br = new BinaryReader(fs);
            //Console.WriteLine(br.PeekChar());

            long blen = fs.Length;

            byte[] barg = new byte[blen];

            barg = br.ReadBytes((int)blen);

            BitArray bat = BitArras.FromByteArray(barg, true);
            BitArras bar = new BitArras(bat);

            bar.BlowBits(8);

            Console.WriteLine(bar.strBits(12));


            bar.BlowBits(12);


            Console.WriteLine(bar.strBits(8));

            byte[] sz = bar.ReadBytes(42, true);

            BitArras.ReverseByteArray(sz);

            String designTitle = UnicodeEncoding.Unicode.GetString(sz);

            Console.WriteLine(designTitle);
            nombo.Text = designTitle;



            Console.WriteLine();

            Console.WriteLine(bar.getpos());

            bar.BlowBits(16);


            sz = bar.ReadBytes(20, true);
            MessageBox.Show(bar.getpos() + " IAM");
            BitArras.ReverseByteArray(sz);

            String designAuthor = UnicodeEncoding.Unicode.GetString(sz);

            authbox.Text = designAuthor;

            Console.WriteLine(designAuthor);

            bar.BlowBits(16);



            sz = bar.ReadBytes(18, true);



            BitArras.ReverseByteArray(sz);

            String designTown = UnicodeEncoding.Unicode.GetString(sz);

            citybox.Text = "" + designTown;

            Console.WriteLine(designTown);



            bar.BlowBits(32);



            Console.WriteLine(bar.getpos());
            sz = bar.ReadBytes(15, false);



            bar.BlowBits(8);

            BitArray palbits = BitArras.FromByteArray(sz, true);

            if (bitord.Checked)
            {
                BitArras.Reverse(palbits);
            }

            BitArras arraspal = new BitArras(palbits);

            sz = arraspal.ReadBytes(15, false);
            Console.WriteLine(BitConverter.ToString(sz));

            if (revbyt.Checked)
            {
                BitArras.ReverseByteArray(sz);
            }

            for (int i = 0; i < 15; i++)
            {
                sz[i] = Form1.findPalIndex(sz[i]);
                Console.WriteLine(sz[i].ToString());
            }

            for (int i = 0; i < trackBar1.Value; i++)
            {
                sz = rot16(sz);
            }

            String ColorPalette = UTF8Encoding.UTF8.GetString(sz);

            if (shuffleBox.Checked)
            {
                Shuffle(sz);
            }

            List <int> cols = new List <int>();

            for (int i = 0; i < sz.Length; i++)
            {
                cols.Add((int)(Color.FromArgb(pallet_r[sz[i]], pallet_g[sz[i]], pallet_b[sz[i]]).GetBrightness()));
            }

            // Array.Sort(cols.ToArray(), sz);
            //  Array.Reverse(sz);



            Console.WriteLine(BitConverter.ToString(sz));
            bar.BlowBits(8);

            byte[] panelType = (bar.ReadBytes(1, true));

            byte ptype = panelType[0];

            Console.WriteLine("Panel Type: " + ptype);

            bar.BlowBits(16);

            //  bar.BlowBits(40);

            int leftData = ((bar.getlen() - 0) - bar.getpos()) - 16
            ;

            Console.WriteLine(leftData.ToString() + "@@@");

            byte[] habytes = bar.createHalfByteArray(leftData / 8);



            Console.WriteLine(habytes.Length.ToString());


            //sz = bar.ReadBytes(leftData/8, true);

            //BitArras.ReverseByteArray(sz);

            //Console.WriteLine(sz[0] );
            //Console.WriteLine();



            // String ImgData = UTF8Encoding.UTF8.GetString(sz);

            Color[] colors =
                new Color[] {
                Color.Blue,
                Color.OrangeRed,
                Color.Orange,
                Color.Tan,
                Color.Lavender,
                Color.Magenta,
                Color.Brown,
                Color.Yellow,
                Color.Indigo,
                Color.Blue,
                Color.ForestGreen,
                Color.Lime,
                Color.White,
                Color.SkyBlue,
                Color.Cyan,
                Color.Green
            };
            if (pairswop.Checked)
            {
                PairSwap(sz);
            }

            // byte tmp = sz[1];
            // sz[1] = sz[7];
            // sz[7] = tmp;

            Bitmap pal = new Bitmap(15, 2);

            groupBox1.Controls.Clear();
            for (int i = 0; i < 15; i++)
            {
                Color me = Color.FromArgb(pallet_r[sz[i]], pallet_g[sz[i]], pallet_b[sz[i]]);

                pal.SetPixel(i, 0, Color.FromArgb(pallet_r[sz[i]], pallet_g[sz[i]], pallet_b[sz[i]]));
                Button newb = new Button();

                newb.Left  = 20 * i;
                newb.Top   = 20;
                newb.Width = 15;

                newb.BackColor = me;
                groupBox1.Controls.Add(newb);
            }

            pictureBox2.Image = pal;

            int    tms = 0;
            Bitmap pic = new Bitmap(32, 32);
            int    off = 0;

            for (int i = 0; i < 32; i++)
            {
                for (int j = 0; j < 32; j++)
                {
                    //pic.SetPixel(j, i, colors[habytes[off]]);
                    //if (habytes[off] < 15)
                    // habytes[off] -= 1;

                    // if (habytes[off] ==255)
                    //     habytes[off] = 13;

                    byte hab = habytes[off];

                    byte uiop = transfromsilly(hab);

                    int habi = (int)hab;


                    byte bty = sz[hab];
                    // MessageBox.Show(bty.ToString());
                    int colindex = sz[uiop];

                    //  Console.WriteLine(colindex);

                    // if (colindex > 128)
                    //    colindex = colindex % 128;
                    tms++;
                    off += 1;
                    pic.SetPixel(j, i, Color.FromArgb(pallet_r[colindex], pallet_g[colindex], pallet_b[colindex]));
                }
            }

            pictureBox1.Image = pic;

            if (printRaw.Checked)
            {
                Console.WriteLine(BitConverter.ToString(habytes));
            }

            br.Close();
        }
示例#2
0
        public SimplePattern(Stream fs)
        {
            BinaryReader br = new BinaryReader(fs);

            long blen = fs.Length;
            byte[] barg = new byte[blen];

            barg = br.ReadBytes((int)blen);

            BitArray bat = BitArras.FromByteArray(barg, true);
            BitArras bar = new BitArras(bat);

               byte[] heed = bar.ReadBytes(1, true);

            if (heed[0] == 0x70)
            {
                bar.ReadBytes(4, true);
            }

            //if (bar.ReadBytes(1, true)[0] != QR_MAGIC)
            //  throw new Exception("This is not a single pattern QR code.\n Pro designs are not yet supported.");
              //  bar.BlowBits(8);
            bar.BlowBits(12);

            designName = ReadUnicodeString(bar, 42);

            bar.BlowBits(16);

            creatorName = ReadUnicodeString(bar, 20);
            MessageBox.Show(bar.getpos() + " IAM");
            bar.BlowBits(16);

            cityName = ReadUnicodeString(bar, 18);

            bar.BlowBits(32);

            design = new NewLeafBitmap();
            design.readPaletteFromArras(bar);

            bar.BlowBits(16);

            byte[] panelType = (bar.ReadBytes(1, true));
            designType = panelType[0];

            bar.BlowBits(8);

            int leftData = ((bar.getlen() - 0) - bar.getpos()) - 16;
            MessageBox.Show((leftData).ToString());
            byte[] habytes = bar.createHalfByteArray(leftData / 8);
            int counter = 0;
            for (int i = 0; i < 32; i++)
                for (int j = 0; j < 32; j++)
                    design.falseColor.SetPixel(j,i, Color.FromArgb(((int)(habytes[counter++]))));

            FileStream fs2 = new FileStream("C:/DATASETS/QRDUMP", FileMode.Create);
            fs.Seek(0, SeekOrigin.
            Begin);

            fs.CopyTo(fs2);
            fs2.Close();
        }