>  기사  >  백엔드 개발  >  C#에서 QR 코드를 생성하는 방법 공유 예

C#에서 QR 코드를 생성하는 방법 공유 예

黄舟
黄舟원래의
2017-09-19 11:19:001981검색

ZXing 클래스 라이브러리를 참조하세요

기능 구현:

1 로고가 있는 QR 코드 생성

2 그림에 QR 코드 그리기

3 그림에 텍스트 그리기

QR 코드 생성

public string CreateQrCode(string md5Str,string name,int sex)
        {
            string str = sex == 1? "先生":"女士";
            string logoPath = AppDomain.CurrentDomain.BaseDirectory + "/logo.png";
            string qrCodePath = path + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg";
            string yqPath = AppDomain.CurrentDomain.BaseDirectory + "/yq2.jpg";
            string yqCardPath = path + TCommon.Md5(DateTime.Now.ToString("yyyyMMddHHmmss")) + ".jpg";
            if (Directory.Exists(path) == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(path);
            }
            Generate3(md5Str,logoPath,qrCodePath);
            Image qrCodeImg = new Bitmap(qrCodePath);
            Image image = new Bitmap(yqPath);
            Graphics ig = Graphics.FromImage(image);
            Font font = new Font("Arial", 38,FontStyle.Bold); 
            Font font2 = new Font("STXINWEI", 38, FontStyle.Bold);
            Brush brush = System.Drawing.Brushes.Black;
            SizeF size = ig.MeasureString(name, font2);
            SizeF size2 = ig.MeasureString(str, font);
            ig.DrawString(name, font, brush, (720-size.Width-size2.Width) /2, 680);
            ig.DrawString(str, font, brush, (720 - size.Width - size2.Width) / 2 + size.Width, 680);
            ig.FillRectangle(Brushes.White, 280, 351, 160, 160);
            ig.DrawImage(qrCodeImg, 285, 356);
            image.Save(yqCardPath);
            return yqCardPath.Substring(2);
        }

图片上生成文字

위 내용은 C#에서 QR 코드를 생성하는 방법 공유 예의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.