zoukankan      html  css  js  c++  java
  • 代码暂存 [获取二唯码并识别保存二唯码]

    public void CreateImage(string imgfile)
    {
    wx_set mWXSet = wx_set.FetchTopOne();
    if (mWXSet.IsNew)
    {
    throw new Exception("未配置与微信交互的相关参数");
    }

    FileInfo mFile = new FileInfo(imgfile);

    if (mFile.Exists && mFile.LastWriteTime.AddMilliseconds(7) > DateTime.Now)
    {
    mFile.Open(FileMode.Open).Close();
    return;
    }
    string accessToken = AccessTokenContainer.TryGetToken(mWXSet.appid, mWXSet.appsecret);
    //int expireSenconds = 0;
    int expireSenconds = 604800;
    CreateQrCodeResult createQrCodeResult = QrCodeApi.Create(accessToken, expireSenconds, 10001);
    if (!string.IsNullOrEmpty(createQrCodeResult.ticket))
    {
    using (MemoryStream stream = new MemoryStream())
    {
    //根据ticket获取二维码
    QrCodeApi.ShowQrCode(createQrCodeResult.ticket, stream);
    //将获取到的二维码图片转换为Base64String格式
    //byte[] imageBytes = stream.ToArray();
    //string base64Image = System.Convert.ToBase64String(imageBytes);
    //由于SqlServerCompact数据库限制最长字符4000,本测试项目将二维码保存到磁盘,正式项目中可直接保存到数据库
    popularizeimagecode =
    WH.Business.Utilities.wjGoddess.SaveQRCodeImage(stream,
    imgfile);

    }
    }
    }

    public static string SaveQRCodeImage(Stream InputStream, string filePath)
    {
    using (Bitmap bmp = new Bitmap(InputStream))
    using (Bitmap bmp2 = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb))
    using (Graphics draw = Graphics.FromImage(bmp2))
    {
    try
    {
    //新建第二个bitmap类型的bmp2变量,我这里是根据我的程序需要设置的。
    //将第一个bmp拷贝到bmp2中
    draw.DrawImage(bmp, 0, 0, bmp.Width, bmp.Height);
    bmp2.Save(filePath);
    LuminanceSource source = new RGBLuminanceSource(bmp2, bmp2.Width, bmp2.Height);
    com.google.zxing.BinaryBitmap bitmap = new com.google.zxing.BinaryBitmap(new HybridBinarizer(source));
    com.google.zxing.Result result;


    result = new MultiFormatReader().decode(bitmap);

    return result.Text;
    }
    catch (ReaderException re)
    {
    MyLog.Log(re.ToString());
    //MessageBox.Show(re.ToString());
    //return;
    }
    finally
    {
    draw.Dispose();
    bmp.Dispose();//释放bmp文件资源
    bmp2.Dispose();
    }
    }
    return "";
    }

  • 相关阅读:
    无刷电机控制基本原理
    SPI 串行Flash闪存W25Q128FV 的使用(STM32F407)_软件篇
    CAN总线简介
    RS-232串口特性
    PLSQL 安装教程
    JS 常用正则表达式备忘录
    JS数组去重
    Js中Map对象的使用
    JS操作字符串
    前端小技巧
  • 原文地址:https://www.cnblogs.com/forhell/p/4932322.html
Copyright © 2011-2022 走看看