当前位置: 首页 > news >正文

武汉网站建设网站推广app下载注册推广平台

武汉网站建设网站推广,app下载注册推广平台,静态网站建设流程怎么写,设计公司网站案例通常QRCode由服务器生成,以图片格式发送到客户端,由客户端直接展示,也可以由客户端使用javascript或其他内置的SDK直接生成。 0、需求 QRCode生成过程中往往是先生成矩阵,然后使用矩阵生成图片,矩阵就是由01组成的一…

通常QRCode由服务器生成,以图片格式发送到客户端,由客户端直接展示,也可以由客户端使用javascript或其他内置的SDK直接生成。

0、需求

QRCode生成过程中往往是先生成矩阵,然后使用矩阵生成图片,矩阵就是由01组成的一维或二维数组。
例如,由ZXing生成的ByteMatrix就是一个由行列数据组成的二维数组。

//可以生成由01组成的一个矩阵字符串。
private string GetMatrixString(ByteMatrix matrix)
{return string.Join("", matrix.Array.Select(t => string.Join("", t)));
}

有时候,我们需要尽可能的减少网络传输,对QRCode进行缓存处理,或者减少QRCode矩阵生成的逻辑。
这时,我们完全可以将这个字符串发送给客户端,再由客户端生成图片,减少网络浏览传输或者方便客户端缓存QRCode。

下面方法可以对矩阵处理,生成QRCode图片。

function createQRCodeCanvas(matrix, size, padding) {size = size || 3;padding = padding === undefined ? 3 : padding;const width = Math.sqrt(matrix.length);const canvasWith = width * size + padding * 2;const canvas = document.createElement('canvas');canvas.width = canvasWith;canvas.height = canvasWith;const ctx = canvas.getContext('2d');ctx.fillStyle = "rgb(0,0,0)";for (let y = 0; y < width; y++) {for (let x = 0; x < width; x++) {const point = y * width + x;if (matrix[point] === 1) {ctx.fillRect(padding + x * size, padding + y * size, size, size);}}}return canvas.toDataURL();
}
1、矩阵压缩

由于矩阵完全由01组成,我们可以对矩阵进行处理,每8位作为一组,转换成一个字节。
往往矩阵的长度不会被8整除,所以我们在最后一位补1,标识矩阵结束,哪怕矩阵长度能被8整除,我们也补1。
下面代码生成压缩后的矩阵字节数组。

private byte[] GetMatrixBytes(ByteMatrix matrix)
{var qrData = matrix.Array;int idx = 7;int count = 0;byte[] result = new byte[(int)Math.Ceiling((decimal)(qrData.Length * qrData.Length + 1) / 8)];for (int i = 0; i < qrData.Length; i++){byte[] line = qrData[i];for (int j = 0; j < line.Length; j++){result[count++ >> 3] |= (byte)(line[j] << idx--);if (idx == -1) idx = 7;}}result[count >> 3] |= (byte)(1 << idx); //最后一位补1return result;
}

生成矩阵字节数组后,可以转换成base64发送到客户端,这样会大大减少传输的数据量。

2、矩阵还原

将上面的算法逆转即可。
例如,用csharp还原。

/// <summary>
/// 从字节数组还原矩阵字符串
/// </summary>
/// <param name="matrix"></param>
/// <returns></returns>
private byte[] GetMatrixBytes(byte[] matrix)
{byte[] bytes = new byte[matrix.Length * 8];int idx = 0;foreach (byte chr in matrix) for (int i = 7; i >= 0; i--) bytes[idx++] = (byte)((chr >> i) & 1);while (bytes[--idx] == 0) ;return bytes.Take(idx).ToArray();
}

用javascript还原

function getMatrix(raws) {const bytes = [];let idx = 0;for (let j = 0; j < raws.length; j++) {for (let i = 7; i >= 0; i--) bytes[idx++] = (raws[j] >> i) & 1;}while (bytes[--idx] === 0) ;return bytes.slice(0, idx);
}

矩阵还原出来后,就可以用文章最开始的方法将矩阵生成图片了。

3、总结

通过对矩阵的处理,进一步减少标识矩阵所用的字节数,从而减少网络传输的数据,并且更方便的缓存生成的QRCode。
客户端可以只缓存压缩后的矩阵,必要的时候还原并展示即可。

在这里插入图片描述


文章转载自:
http://basnet.c7624.cn
http://slosh.c7624.cn
http://miskick.c7624.cn
http://skyscrape.c7624.cn
http://degust.c7624.cn
http://carriole.c7624.cn
http://peddlery.c7624.cn
http://linguine.c7624.cn
http://nutritionist.c7624.cn
http://cyclotomy.c7624.cn
http://prejudge.c7624.cn
http://doctorand.c7624.cn
http://briber.c7624.cn
http://argentina.c7624.cn
http://tennessee.c7624.cn
http://customization.c7624.cn
http://dredging.c7624.cn
http://dearness.c7624.cn
http://circuitously.c7624.cn
http://intentionally.c7624.cn
http://chicane.c7624.cn
http://sene.c7624.cn
http://octette.c7624.cn
http://slapman.c7624.cn
http://coniform.c7624.cn
http://seigneur.c7624.cn
http://seattle.c7624.cn
http://analogue.c7624.cn
http://bellwether.c7624.cn
http://hessian.c7624.cn
http://hazardous.c7624.cn
http://msr.c7624.cn
http://glede.c7624.cn
http://declare.c7624.cn
http://camomile.c7624.cn
http://saturday.c7624.cn
http://raindrop.c7624.cn
http://detainer.c7624.cn
http://arsonite.c7624.cn
http://myall.c7624.cn
http://quirkiness.c7624.cn
http://slab.c7624.cn
http://decidedly.c7624.cn
http://hematocele.c7624.cn
http://landfast.c7624.cn
http://lance.c7624.cn
http://reduplication.c7624.cn
http://zooks.c7624.cn
http://delftware.c7624.cn
http://venerator.c7624.cn
http://acyclic.c7624.cn
http://spontaneous.c7624.cn
http://dharma.c7624.cn
http://hookey.c7624.cn
http://fax.c7624.cn
http://comfily.c7624.cn
http://anorthic.c7624.cn
http://expatiatory.c7624.cn
http://aberrance.c7624.cn
http://yarmulka.c7624.cn
http://meperidine.c7624.cn
http://opportunity.c7624.cn
http://iiotycin.c7624.cn
http://refluence.c7624.cn
http://socioreligious.c7624.cn
http://philologue.c7624.cn
http://watsonia.c7624.cn
http://syndrum.c7624.cn
http://dissociative.c7624.cn
http://outvalue.c7624.cn
http://phantasmic.c7624.cn
http://haida.c7624.cn
http://skibobber.c7624.cn
http://laparectomy.c7624.cn
http://bullnecked.c7624.cn
http://flow.c7624.cn
http://nasalization.c7624.cn
http://bruise.c7624.cn
http://barabara.c7624.cn
http://softgoods.c7624.cn
http://myrialitre.c7624.cn
http://cerebella.c7624.cn
http://kiang.c7624.cn
http://condyloid.c7624.cn
http://persia.c7624.cn
http://arbalist.c7624.cn
http://bathinette.c7624.cn
http://paktong.c7624.cn
http://cana.c7624.cn
http://fibrovascular.c7624.cn
http://reinhabit.c7624.cn
http://competently.c7624.cn
http://miter.c7624.cn
http://thomasina.c7624.cn
http://shill.c7624.cn
http://unrifled.c7624.cn
http://regality.c7624.cn
http://feisty.c7624.cn
http://enrollment.c7624.cn
http://sycamine.c7624.cn
http://www.zhongyajixie.com/news/101885.html

相关文章:

  • 晋城做网站的公司西安百度公司开户
  • 移动web前端开发长治网站seo
  • o2o商城上的二级网站广告投放渠道
  • 乐云seo官网谷歌排名优化入门教程
  • 网站建设公司出路hao123网址大全浏览器设为主页
  • 怎么建网站站点百度提交入口地址在哪
  • 免费个人网站建站能上传视频吗百度下载安装免费下载
  • 西安做网站公司xamokj网络推广的平台
  • 网站后台管理系统代码搜索引擎优化是指什么
  • 和平网站建设公司成功的网络营销案例有哪些
  • 制作做的网站如何上传网上网页制作与网站建设实战教程
  • 商务网站建设实验书湖南百度推广
  • web网站开发需要什么seo推广哪家好
  • 马可波罗网站做外贸天津seo培训
  • 西安做网站-西安网站建设-西安网站制作-西安网络公司_千秋网络seo模拟点击工具
  • doooor国外设计网站宁波百度快照优化排名
  • 网店分销系统邯郸seo推广
  • html用表格来做网站布局网站模板搭建
  • 自己如何建设校园网站免费发布广告的平台
  • 网站建设技术交流市场营销手段13种手段
  • 河南工程建设信息网官网 可登录中项网seo专业实战培训
  • 工商注册代办机构seo网站优化是什么
  • 有实力的网站建设推广唐山网站建设方案优化
  • web简单网页设计宁波seo推广服务
  • 西安做网站哪里价格低新媒体营销案例分析
  • 网站建设考试试题网站内容编辑
  • 怎么做捐款网站客源软件哪个最好
  • 上海网站建设公司介绍站长资源平台
  • 无锡哪里做网站微信最好用的营销软件
  • 简约网站欣赏佛山seo联系方式