zoukankan      html  css  js  c++  java
  • 将字符串转化为条形码,在将canvas转化为图片

    利用jsBarCode可将字符串转为条形码

    先创建一个画布

    <canvas id="barcode" class="barcode1"></canvas>
    

    再用JsBarcode进行绘画

    import JsBarcode from 'jsbarcode'
    // displayValue是设定是否默认展示二维码对应的文字
    JsBarcode("#barcode", 'EMS22121212', {displayValue: false});
    

    canvas转img

    主要是用toDataURL将canvas解析为img标签src所需要的字段

    再对元素进行增删操作,是img放入页面dom

    function canvasToImg (className, height) {
          const barcode = document.getElementsByClassName(className)[0]
          const barcodeFather = barcode.parentNode
          let img = document.createElement('img')
          img.src = barcode.toDataURL("image/png")
          barcodeFather.insertBefore(img, barcode)
          if (height) {
            img.style.height = `${height}px`
          } else {
            img.width = barcode.width;
            img.height = barcode.height;
          }
          barcodeFather.removeChild(barcode);
        }
    
  • 相关阅读:
    NET領域模型(1)
    oracle 函數索引(1)
    oracle 動態SQL(1)
    WF事件驱动(5)
    WF事件驱动(3)
    WF事件驱动(4)
    HP LoadRunner 11.00 新鲜尝
    Tomcat配置优化要点
    WebSphere性能诊断与调优
    性能测试工具、监控工具
  • 原文地址:https://www.cnblogs.com/axu1997/p/14821403.html
Copyright © 2011-2022 走看看