最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用javascript解析二維碼的三種方式

 更新時(shí)間:2021年11月08日 11:02:21   作者:zz  
這篇文章主要給大家分享使用javascript解析二維碼的三種方式,二維碼就是將我們能看懂的文字語(yǔ)言,以機(jī)器語(yǔ)言的形式存儲(chǔ)了起來(lái)。其中黑色小方塊代表的是1,白色小方塊代表的是0,黑白相間的圖案其實(shí)就是一串編碼,掃碼的過(guò)程就是翻譯這些編碼的過(guò)程,需要的朋友可以參考一下

一、使用javascript解析二維碼

1、二維碼是什么

二維碼就是將我們能看懂的文字語(yǔ)言,以機(jī)器語(yǔ)言的形式存儲(chǔ)了起來(lái)。其中黑色小方塊代表的是1,白色小方塊代表的是0,黑白相間的圖案其實(shí)就是一串編碼,掃碼的過(guò)程就是翻譯這些編碼的過(guò)程。還要值得注意的地方就是,在它的邊上都有三個(gè)大方塊,這主要是在起定位作用。三個(gè)點(diǎn)能確定一個(gè)面,這能保證我們?cè)趻叽a時(shí),不管手機(jī)怎樣放置都能得到特定的信息

二、qrcode-parser

這是一個(gè)沒(méi)有依賴的二維碼前端解析工具。優(yōu)點(diǎn)是包小,輕量級(jí)工具,缺點(diǎn)不會(huì)調(diào)用攝像頭。需要編寫(xiě)調(diào)用攝像頭的代碼。

1、安裝方式

npm add  qrcode-parser

2、使用方式

import qrcodeParser from 'qrcode-parser'

let img = '';
qrcodeParser().then(res =>{
    console.log(res)
})

三、ngx-qrcode2

一個(gè)集成到angular的二維碼生成工具。只能生成,不能讀取。

1、安裝方式

npm add ngx-qrcode2

2、使用方式

Appmodule 中導(dǎo)入模塊:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxQRCodeModule } from 'ngx-qrcode2';

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxQRCodeModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.html 插入的模板:

<div style="text-align:center">
  <h1>ngx-qrcode2 demo</h1>
</div>

<ngx-qrcode
      [qrc-element-type]="elementType"
      [qrc-value] = "value"
      qrc-class = "aclass"
      qrc-errorCorrectionLevel = "L">
</ngx-qrcode>

在app.component.ts 中添加代碼:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'app';
  elementType = 'url';
  value = 'Techiediaries';
}

四、前端生成二維碼

1、安裝方式

npm install @techiediaries/ngx-qrcode --save

2、使用方式

在Appmodule中導(dǎo)入模塊:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { QrCodeAllModule } from 'ngx-qrcode-all';
import { AppComponent } from './app.component';

@NgModule({
    imports: [
        CommonModule,
        QrCodeAllModule
    ],
    declarations: [
        AppComponent
    ]
})
export class AppModule {
    constructor() {}
}

3、案例一:生成二維碼的代碼模板

<div id="qrcodeid">
 <qr-code-all [qrCodeType]="url"
     [qrCodeValue]="'SK is the best in the world!'"
     [qrCodeVersion]="'1'"
     [qrCodeECLevel]="'M'"
     [qrCodeColorLight]="'#ffffff'"
     [qrCodeColorDark]="'#000000'"
     [width]="11"
     [margin]="4"
     [scale]="4"
     [scanQrCode]="false">
 </qr-code-all>
</div>

4、案例二:讀取二維碼

<div id="qrcodeid">
 <qr-code-all [canvasWidth]="640"
     [canvasHeight]="480"
     [debug]="false"
     [stopAfterScan]="true"
     [updateTime]="500"
     (onCapture)="captureImage($event)"
     [scanQrCode]="true">
 </qr-code-all>
</div>

到此這篇關(guān)于使用javascript解析二維碼的三種方式的文章就介紹到這了,更多相關(guān)javascript解析二維碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

临安市| 浦江县| 亚东县| 上思县| 定州市| 杭锦旗| 大理市| 正定县| 开江县| 璧山县| 维西| 凤山县| 大田县| 祁连县| 沙洋县| 西昌市| 石家庄市| 旌德县| 新巴尔虎右旗| 涿鹿县| 潍坊市| 克东县| 镇江市| 渝北区| 临高县| 邵东县| 四子王旗| 扎兰屯市| 屏东市| 政和县| 项城市| 祁门县| 麦盖提县| 康保县| 芮城县| 绿春县| 凯里市| 黔西县| 新营市| 仙游县| 九寨沟县|