Skip to content

Instantly share code, notes, and snippets.

View yushulx's full-sized avatar

Xiao Ling yushulx

View GitHub Profile
<input type="file" id="barcode-file" onchange="loadfile()" accept=".jpg,.jpeg,.png,.bmp" />
function loadfile() {
let img = new Image();
var reader = new FileReader();
reader.onload = function (evt) {
img.onload = function () {
if (img.width > maxLength) {
img.height = maxLength * img.height / img.width
img.width = maxLength;
<style>
#container {
position: relative;
}
#imageCanvas {
position: relative;
z-index: 1;
}
@yushulx
yushulx / barcode-region-detection.htm
Created October 9, 2020 08:34
A simple region selection tool for speeding up barcode detection
<!DOCTYPE html>
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.js" data-productKeys="LICENSE-KEY"></script>
<style>
#container {
position: relative;
}
<apex:page >
<html>
<head>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/dbr.js" data-productKeys="LICENSE-KEY"></script>
</head>
<body>
<h1>Dynamsoft JavaScript Barcode SDK</h1>
<p></p>
window.jsFunctions = {
init: function(obj) {
dotnetRef = obj;
},
selectFile: function () {
let input = document.createElement("input");
input.type = "file";
input.onchange = async function () {
let file = input.files[0];
try {
<button class="btn btn-primary" @onclick="ReadBarcodes">Read Barcodes from Files</button>
@code {
private static String result = "No Barcode Found";
protected override void OnInitialized()
{
JSRuntime.InvokeVoidAsync("jsFunctions.init", DotNetObjectReference.Create(this));
}
public async Task ReadBarcodes()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>BlazorBarcodeSample</title>
<base href="/" />
<link href="css/bootstrap/bootstrap.min.css" rel="stylesheet" />
<link href="css/app.css" rel="stylesheet" />
function acquireImage() {
if (DWServiceObject) {
var onSuccess, onFailure;
onSuccess = onFailure = function () {
DWServiceObject.CloseSource();
};
var deviceConfiguration = {
SelectSourceByIndex: 0,
IfShowUI: false,
function createScanObject(ip) {
var dwtConfig={WebTwainId:ip, Host: ip, UseLocalService:'true'};
Dynamsoft.WebTwainEnv.CreateDWTObjectEx(dwtConfig, function (dwt) {
DWServiceObject = dwt;
DWServiceObject.RegisterEvent('OnPostTransferAsync', function(outputInfo){
DWServiceObject.ConvertToBlob(
[DWServiceObject.ImageIDToIndex(outputInfo.imageId)],
Dynamsoft.EnumDWT_ImageType.IT_PNG,
function (result, indices, type) {
DWObject.LoadImageFromBinary(
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<script src="dist/dynamsoft.webtwain.min.js"></script>
</head>
<body>
<input type="button" value="Scan" onclick="AcquireImage();" />
<div id="dwtcontrolContainer"></div>
<script type="text/javascript">