Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            MultiFormatWriter mutiWriter = new MultiFormatWriter();
            BitMatrix         bm         = mutiWriter.encode("http://www.vgo2013.com/WebService/QR.aspx?ID=" + "111111", BarcodeFormat.QR_CODE, 300, 300);

            ZXing.Rendering.BitmapRenderer br = new ZXing.Rendering.BitmapRenderer();
            Bitmap img = br.Render(bm, BarcodeFormat.QR_CODE, "http://www.vgo2013.com/WebService/QR.aspx?ID=" + "111111");

            img = KiResizeImage(img, 90, 90, 0);
            string filename = System.Environment.CurrentDirectory + "\\QR" + DateTime.Now.Ticks.ToString() + ".jpg";

            img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
Ejemplo n.º 2
0
        public Bitmap serializePattern()
        {
            MemoryStream ms = new MemoryStream();

            BinaryWriter br = new BinaryWriter(ms);

            br.Write(padBytes(0));

            byte[] nameBytes = UnicodeEncoding.Unicode.GetBytes(designName);
            int pad = 41 - nameBytes.Length;

            br.Write(nameBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            // These are *1 and 2, the first two bytes of the unique id.
            br.Write(padBytes(2));

            byte[] creatorBytes = UnicodeEncoding.Unicode.GetBytes(creatorName);
            pad = 20 - nameBytes.Length;

            br.Write(creatorBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            // Special bytes 3 and 4.
            br.Write(padBytes(2));

            byte[] cityBytes = UnicodeEncoding.Unicode.GetBytes(cityName);

            pad = 18 - nameBytes.Length;

            br.Write(cityBytes);
            if (pad > 0)
            br.Write(padBytes(pad));

            br.Write(padBytes(4));

            for (int i = 0; i < 15; i++)
            {
                br.Write(new byte[]{NewLeafBitmap.findPalIndexInv(this.design.filepal[i])});
            }

            // Special byte 7.
            br.Write(padBytes(1));

            br.Write(new byte[] { (byte)0x0A });
            br.Write(new byte[] { (byte)0x09 });

            br.Write(padBytes(2));

            BitArray halfBytes = new BitArray(1024*4);

            int counter = 0;

            List<byte> blist = new List<byte>();

            for (int i = 0; i < 32; i++)
                for (int j = 0; j < 32; j++)
                {
                    blist.Add((byte)(this.design.falseColor.GetPixel(j,i).ToArgb()));

                }

            int counterR = 0;
            for (int i = 0; i < blist.Count; )
            {
                BitArray halfWord = new BitArray(new byte[] { blist[i] });
                halfBytes[counterR + 4] =     halfWord[0];
                halfBytes[counterR + 5]= halfWord[1];
                halfBytes[counterR + 6] = halfWord[2];
                halfBytes[counterR + 7] = halfWord[3];
                halfWord = new BitArray(new byte[] { blist[i + 1] });
                halfBytes[counterR + 0] = halfWord[0];
                halfBytes[counterR + 1] = halfWord[1];
                halfBytes[counterR + 2] = halfWord[2];
                halfBytes[counterR + 3] = halfWord[3];
                counterR += 8;

                i += 2;
            }

            FileStream fs = File.Open("C:/DATASETS/serialize.txt", FileMode.Create);
               // ms.CopyTo(fs);

            byte[] junk = copyOctetwiseReverse(ms.ToArray());
            BitArray a = new BitArray(junk);

              //  a = a.Append(new BitArray(4));

            BitArray ab = a.Append(halfBytes);

            BitArray header = new BitArray(new byte[]{QR_MAGIC});
            header.Reverse();
            BitArray header2 = new BitArray(new byte[] { 38 });
            header2.Reverse();

            BitArray header3 = new BitArray(4);

            header3.Set(1, true);
            header3.Set(1, true);
            header3.Set(0, true);
            header3.Set(0, true);

            //header = header2.Prepend(header);

             BitArray all = header.Append(header2);
             all = all.Append(header3);

             all = all.Append(ab);

            byte[] omni = all.ToByteArray();

            MessageBox.Show(BitConverter.ToString(omni));

            fs.Write(omni,0,omni.Length);

               // fs.WriteByte(0xEC);
              //  fs.WriteByte(0x11);
               // fs.WriteByte(0xEC);
               // fs.WriteByte(0x11);
            System.Text.Encoding iso_8859_1 = System.Text.Encoding.GetEncoding("iso-8859-1");

            QRCodeWriter qrw = new QRCodeWriter();

               // for (int i = 0; i < omni.Length; i++)
               // {
               //     omni[i] = (byte)((sbyte)omni[i]);
               // }

            Dictionary<EncodeHintType, object> h = new Dictionary<EncodeHintType, object>();
            h.Add(ZXing.EncodeHintType.CHARACTER_SET, "CP437");

            h.Add(ZXing.EncodeHintType.DISABLE_ECI, true);
            h.Add(ZXing.EncodeHintType.ERROR_CORRECTION,ZXing.QrCode.Internal.ErrorCorrectionLevel.H);

            ZXing.QrCode.QrCodeEncodingOptions qrec = new QrCodeEncodingOptions();

            var writer = new BarcodeWriter
            {
                Format = BarcodeFormat.QR_CODE,
                Options = new QrCodeEncodingOptions
                {
                    Height = 188,
                    Width = 188,
                    CharacterSet = "CP437",
                    PureBarcode = true,
                    ErrorCorrection = ZXing.QrCode.Internal.ErrorCorrectionLevel.L,
                    DisableECI = false,

                }

            };

            char[] chars = new char[omni.Length];

            for (int i = 0; i < omni.Length; i++)
            {
                chars[i] = (char) omni[i];
            }

            ZXing.Common.BitMatrix bmx =  writer.
               Encode(Encoding.GetEncoding("CP437").GetString(omni));//qrw.encode(new String(), ZXing.BarcodeFormat.QR_CODE, 300, 300);

            //bmx = createBinQRCode(omni, omni.Length, 0);

            fs.Close();

            ms.Close();

              //return bmx.ToBitmap();

               ZXing.BarcodeWriter ss= new ZXing.BarcodeWriter();

               ZXing.IBarcodeWriter reader = new BarcodeWriter();

             ZXing.Rendering.BitmapRenderer bmpr = new ZXing.Rendering.BitmapRenderer();
             MessageBox.Show(Encoding.GetEncoding("CP437").GetString(omni).Substring(0, 10));
             return bmpr.Render(bmx, writer.Format,  Encoding.GetEncoding("CP437").GetString(omni));

            //   Gma.QrCodeNet.Encoding.QrEncoder hi = new Gma.QrCodeNet.Encoding.QrEncoder();
             //  Gma.QrCodeNet.Encoding.QrCode qr = new Gma.QrCodeNet.Encoding.QrCode();
             //

             //  hi.ErrorCorrectionLevel = Gma.QrCodeNet.Encoding.ErrorCorrectionLevel.L;

             //  hi.TryEncode(omni, out qr);

             //  SVGRenderer svg = new SVGRenderer(new FixedModuleSize(6, QuietZoneModules.Two), new FormColor(Color.Black), new FormColor(Color.White));

               // FileStream FSX = new FileStream("C:/DATASETS/QR.svg", FileMode.Create);
            //svg.WriteToStream(qr.Matrix, FSX);
              //  FSX.Close();

             // Bitmap bmp2 = new Bitmap(qr.Matrix.Width, qr.Matrix.Height);
             //  for (int i = 0; i < qr.Matrix.Width; i++)
             //      for (int j = 0; j < qr.Matrix.Height; j++)
             //          bmp2.SetPixel(i, j, qr.Matrix.InternalArray[i, j] ? Color.Black : Color.White);

             //  bmp2.Save("C:/DATASETS/gma");

            //   return bmp2;
        }
Ejemplo n.º 3
0
        private void GetCouponData(object strService)
        {
            Object o = new Object();

            lock (o)
            {
                while (!bGDateIsExit)
                {
                    try
                    {
                        Thread.Sleep(2000);
                        DataSet dsPhoto = wsGetPrindCode.GetPrintPhoto(strSiteCode, strClientID);
                        if (null != dsPhoto && dsPhoto.Tables.Count > 0 && dsPhoto.Tables[0].Rows.Count > 0)
                        {
                            wsGetPrindCode.UpdatePrintState(strHappyPhotoID, "2");

                            strHappyPhotoID = dsPhoto.Tables[0].Rows[0]["ID"].ToString();
                            strPrintCode    = dsPhoto.Tables[0].Rows[0]["PrintCode"].ToString();
                            //strImg = "http://localhost:1156/HP_Photo/" + dsPhoto.Tables[0].Rows[0]["Img"].ToString();
                            strImg        = "http://114.215.108.27//HP_Photo/" + dsPhoto.Tables[0].Rows[0]["Img"].ToString();
                            strAttachText = dsPhoto.Tables[0].Rows[0]["AttachText"].ToString();

                            strPrintImg = "PrintPhoto." + strImg.Split('.').Last();
                            //取打印的图片
                            using (System.Net.WebClient wc = new System.Net.WebClient())
                            {
                                wc.Headers.Add("User-Agent", "Chrome");
                                wc.DownloadFile(strImg, Application.StartupPath + "/" + strPrintImg);
                            }

                            //生成二维码

                            MultiFormatWriter mutiWriter      = new MultiFormatWriter(); //new com.google.zxing.MultiFormatWriter();
                            BitMatrix         bm              = mutiWriter.encode("http://www.vgo2013.com/PalmShop/ShopCode/CodeAward.aspx?ID=" + strHappyPhotoID, BarcodeFormat.QR_CODE, 300, 300);
                            ZXing.Rendering.BitmapRenderer br = new ZXing.Rendering.BitmapRenderer();
                            Bitmap img = br.Render(bm, BarcodeFormat.QR_CODE, "http://www.vgo2013.com/PalmShop/ShopCode/CodeAward.aspx?ID=" + strHappyPhotoID);
                            img = KiResizeImage(img, 65, 65, 0);
                            string filename = System.Environment.CurrentDirectory + "\\log.jpg";
                            img.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);

                            #region 打印过程
                            //printDocument.PrinterSettings.PrinterName = "TM58";//设置打印机

                            //printDocument.PrinterSettings.PrinterName = "Microsoft XPS Document Writer";
                            printDocument.PrinterSettings.PrinterName = "PhotoPrint";
                            //设置页边距
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Left   = 0;
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Top    = 0;
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Right  = 0;
                            printDocument.PrinterSettings.DefaultPageSettings.Margins.Bottom = 0;

                            printDocument.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 290, 414); //页面大小
                            printDocument.DefaultPageSettings.Landscape = false;                                                     //横向打印

                            //打印开始前
                            printDocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
                            //打印输出(过程)
                            printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);
                            //打印结束
                            printDocument.EndPrint += new PrintEventHandler(printDocument_EndPrint);

                            printDocument.Print();
                            //PrintDialog pd = new PrintDialog();
                            //pd.Document = printDocument;
                            //if (DialogResult.OK == pd.ShowDialog())
                            //{
                            //    //预览
                            //    PrintPreviewDialog ppd = new PrintPreviewDialog();
                            //    ppd.Document = printDocument;
                            //    if (DialogResult.OK == ppd.ShowDialog()) printDocument.Print();
                            //}
                            #endregion

                            this.BeginInvoke(new Action(() =>
                            {
                            }));
                        }
                        Application.DoEvents();
                        Thread.Sleep(2000);
                    }
                    catch //(Exception ex)
                    {
                        //MessageBox.Show(ex.Message);
                        Thread.Sleep(20000);
                    }
                }
            }
        }