溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

使用javascript解析二維碼的三種方式分別是什么

發(fā)布時間:2021-11-08 12:52:26 來源:億速云 閱讀:435 作者:柒染 欄目:開發(fā)技術(shù)

使用javascript解析二維碼的三種方式分別是什么,針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

一、使用javascript解析二維碼

1、二維碼是什么

二維碼就是將我們能看懂的文字語言,以機器語言的形式存儲了起來。其中黑色小方塊代表的是1,白色小方塊代表的是0,黑白相間的圖案其實就是一串編碼,掃碼的過程就是翻譯這些編碼的過程。還要值得注意的地方就是,在它的邊上都有三個大方塊,這主要是在起定位作用。三個點能確定一個面,這能保證我們在掃碼時,不管手機怎樣放置都能得到特定的信息

二、qrcode-parser

這是一個沒有依賴的二維碼前端解析工具。優(yōu)點是包小,輕量級工具,缺點不會調(diào)用攝像頭。需要編寫調(diào)用攝像頭的代碼。

1、安裝方式

npm add  qrcode-parser

2、使用方式

import qrcodeParser from 'qrcode-parser'

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

三、ngx-qrcode2

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

1、安裝方式

npm add ngx-qrcode2

2、使用方式

Appmodule 中導入模塊:

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 >
  <h2>ngx-qrcode2 demo</h2>
</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中導入模塊:

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解析二維碼的三種方式分別是什么問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI