c#如何產生二維碼的樣本分享

來源:互聯網
上載者:User
引用ZXing類庫

實現功能:

1產生帶有Logo二維碼

2 將二維碼繪製到圖片上

3 圖片上繪製文字

產生二維碼

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);        }圖片上產生文字
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.