Exemplo n.º 1
0
        public static string CreateQrCode(string scanUrl, out string squarePicUrl)
        {
            squarePicUrl = null;
            try
            {
                string logo_png = HttpContext.Current.Server.MapPath("~/qrcode_logo.png");
                Bitmap bmp      = QrCodeHelper.CreateQrCode(scanUrl, logo_png);
                //int borderOffset = 30;

                //int h = bmp.Height + borderOffset * 2;
                //int w = h * 9 / 5;
                //Bitmap tmpBmp = new Bitmap(w, h);

                //int offsetX = (tmpBmp.Width - tmpBmp.Height) / 2 + borderOffset;
                //int offsetY = borderOffset;
                //Graphics g = Graphics.FromImage(tmpBmp);
                //g.FillRectangle(Brushes.White, 0, 0, tmpBmp.Width, tmpBmp.Height);
                //g.DrawImage(bmp, offsetX, offsetY, bmp.Width, bmp.Height);
                int      w      = bmp.Width;
                int      h      = bmp.Height;
                Bitmap   tmpBmp = new Bitmap(w + 10, h + 10);
                Graphics g      = Graphics.FromImage(tmpBmp);
                g.FillRectangle(Brushes.White, 0, 0, tmpBmp.Width, tmpBmp.Height);
                g.DrawImage(bmp, 5, 5, w, h);

                string filename = "/pics/qrcode/" + DateTime.Today.ToString("yyyyMM") + "/" + DateTime.Today.ToString("dd") + "/" + Guid.NewGuid().ToString("N") + ".png";
                string fullpath = HttpContext.Current.Server.MapPath("~" + filename);
                string dir      = System.IO.Path.GetDirectoryName(fullpath);
                if (!System.IO.Directory.Exists(dir))
                {
                    System.IO.Directory.CreateDirectory(dir);
                }
                tmpBmp.Save(fullpath);

                string squareFullpath = fullpath.Replace(".png", "_square.png");
                bmp.Save(squareFullpath);

                squarePicUrl = filename.Replace(".png", "_square.png").Replace("\\", "/");

                return(filename.Replace("\\", "/"));
            }
            catch (Exception ex)
            {
                LogHelper.WriteError("二维码管理", "生成QRCode图片失败", ex);
            }
            finally
            {
                GC.Collect();
            }
            return(null);
        }
Exemplo n.º 2
0
        private async void ConnectAsHost(string username)
        {
            await WebSocketClient.Instance.ConnectToServerAsync();

            WebSocketClient.Instance.RegisterForMessage <LoginResponse>(HandleLoginResponse);
            WebSocketClient.Instance.RegisterForMessage <PlayerJoinedResponse>(HandlePlayerJoined);
            WebSocketClient.Instance.RegisterForMessage <TimerResponse>(HandleTimerResponse);

            await WebSocketClient.Instance.SendMessageAsync(new LoginMessage()
            {
                @event = "login", username = username
            });

            GameLogic.Instance.Self = new Player()
            {
                PlayerName = username
            };
            QrCodeHelper.CreateQrCode(username);
        }
Exemplo n.º 3
0
        private async void btnImg_Clicked(object sender, EventArgs e)
        {
            await QrCodeHelper.CreateQrCode("test alex");

            ImageQr.Source = QrCodeHelper.img;
        }