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

公司怎样建自己网站中国建设工程协会标准网站

公司怎样建自己网站,中国建设工程协会标准网站,wordpress开店铺,深圳网站建设定制开发需求背景 前期在做项目的时候#xff0c;有一个需求是说要生成一张条形码#xff0c;并且呢将条形码插入到 excel 中去#xff0c;但是之前一直没有搞过找个条形码或者是二维码#xff0c;最后是做出来了#xff0c;这里呢就先看看怎么生成#xff0c;后面再抽时间来写写… 需求背景 前期在做项目的时候有一个需求是说要生成一张条形码并且呢将条形码插入到 excel 中去但是之前一直没有搞过找个条形码或者是二维码最后是做出来了这里呢就先看看怎么生成后面再抽时间来写写怎么实现条形码插入到 excel 中去。 开始搭建 引入对应的 zxing 依赖包 dependencygroupIdcom.google.zxing/groupIdartifactIdcore/artifactIdversion3.4.1/version /dependencydependencygroupIdcom.google.zxing/groupIdartifactIdjavase/artifactIdversion3.4.1/version /dependency条形码生成与读取 这里呢我就不赘述太多了因为这个就是一个工具类设置好对应的参数执行指定的方法就可以了比较简单具体的生成代码以及读取条形码的代码如下 import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer;import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.util.HashMap; import java.util.Map;public class BarCodeUtils {/*** generateCode 根据code生成相应的一维码** param file 一维码目标文件* param code 一维码内容* param width 图片宽度* param height 图片高度*/public static void generateCode(File file, String code, int width, int height) {//定义位图矩阵BitMatrixBitMatrix matrix null;try {// 使用code_128格式进行编码生成100*25的条形码MultiFormatWriter writer new MultiFormatWriter();MapEncodeHintType, Object hints new HashMap();hints.put(EncodeHintType.CHARACTER_SET, UTF-8);//定义编码参数 这里可以设置条形码的格式matrix writer.encode(code, BarcodeFormat.CODE_128, width, height, hints);//matrix writer.encode(code,BarcodeFormat.EAN_13, width, height, hints);} catch (WriterException e) {e.printStackTrace();}//将位图矩阵BitMatrix保存为图片try (FileOutputStream outStream new FileOutputStream(file)) {assert matrix ! null;ImageIO.write(MatrixToImageWriter.toBufferedImage(matrix), png, outStream);outStream.flush();} catch (Exception e) {e.printStackTrace();}}/*** readCode 读取一张一维码图片** param file 一维码图片名字或者是文件路径*/public static void readCode(File file) {try {BufferedImage image ImageIO.read(file);if (image null) {return;}LuminanceSource source new BufferedImageLuminanceSource(image);BinaryBitmap bitmap new BinaryBitmap(new HybridBinarizer(source));MapDecodeHintType, Object hints new HashMap();hints.put(DecodeHintType.CHARACTER_SET, UTF-8);hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);Result result new MultiFormatReader().decode(bitmap, hints);System.out.println(条形码内容: result.getText());} catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) throws Exception {generateCode(new File(D:\\barcode.png), 123456789012, 500, 250);readCode(new File(D:\\barcode.png));}}执行下 对应的文件 二维码生成与读取 上面我们看了下条形码的生成与读取那么我们来看下二维码怎么生成 import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; import com.google.zxing.client.j2se.MatrixToImageWriter; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.File; import java.util.HashMap; import java.util.Map;public class QRCodeUtils {//生成二维码public static void generateQRCode(String content, int width, int height, String filePath) throws Exception {String format png;MapEncodeHintType, Object hints new HashMap();hints.put(EncodeHintType.CHARACTER_SET, UTF-8); //设置编码hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); //设置容错等级hints.put(EncodeHintType.MARGIN, 1); // 设置边距BitMatrix bitMatrix new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);QRCodeUtils.outputQRCode(bitMatrix, format, filePath);}private static void outputQRCode(BitMatrix matrix, String format, String filePath) throws Exception {MatrixToImageWriter.writeToPath(matrix, format, java.nio.file.Paths.get(filePath));}//读取二维码public static void readQrCode(File file) {MultiFormatReader reader new MultiFormatReader();try {BufferedImage image ImageIO.read(file);BinaryBitmap binaryBitmap new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));MapDecodeHintType, Object hints new HashMap();hints.put(DecodeHintType.CHARACTER_SET, utf-8);//设置编码Result result reader.decode(binaryBitmap, hints);System.out.println(解析结果: result.toString());System.out.println(二维码格式: result.getBarcodeFormat());System.out.println(二维码文本内容: result.getText());} catch (Exception e) {e.printStackTrace();}}public static void main(String[] args) throws Exception {String filePath D:\\qrcode.png;generateQRCode(https://www.baidu.com, 300, 300, filePath);readQrCode(new File(filePath));}}执行下 对应的文件 支持的格式源码部分 我们可以点击看下源码 BarcodeFormat 类中支持的各种格式这里是将所有的都给枚举出来了大家需要用到的时候再具体查看吧 public enum BarcodeFormat {AZTEC,CODABAR,CODE_39,CODE_93,CODE_128,DATA_MATRIX,EAN_8,EAN_13,ITF,MAXICODE,PDF_417,QR_CODE,RSS_14,RSS_EXPANDED,UPC_A,UPC_E,UPC_EAN_EXTENSION;private BarcodeFormat() {} }
http://www.w-s-a.com/news/331938/

相关文章:

  • 网站编辑及seo招聘上海做网站公司做网站的公司
  • 杭州四喜做网站建设么ja.wordpress.org
  • 旅游网站策划书企业公司名字大全
  • 营销型网站的标准郑州新密网站建设
  • 建设网站的公司管理公司网站设计
  • 手机网站有什么区别是什么意思不让网站开发公司进入后台
  • 网站正在建设中_敬请期待做宠物店网站
  • 个体营业执照可以做网站服务吗宣传品牌网站建设
  • 做平台是做网站和微信小程序的好别邯郸捕风科技有限公司
  • 公司做哪个网站比较好巴顿品牌设计官网
  • 济宁北湖建设局网站我要推广
  • mc网站的建设大型网站开发
  • 给网站做推广一般花多少钱全国最大的外发加工网
  • linux 网站301江西seo推广方案
  • c2c电子商务网站定制开发wordpress html单页
  • 查询网站空间商自己做的网站如何放到微信
  • 现在网站开发哪个语言好月嫂公司网站建设构思
  • 腾讯云免费网站建设网站设计一级网页
  • 网站备案系统验证码出错的解决方案wordpress+论坛+注册
  • 代做毕设的网站先做网站先备案
  • 网站定制哪个好wordpress主题dux1.9
  • 怎么自己做网站地图网站建设弹窗代码
  • wordpress 作品集网站企业做网站建设的好处
  • 公司开发的网站健身网站开发项目总结
  • 怎样做游戏网站网站建设万首先金手指14
  • 英德建设局网站龙岩网上房地产网
  • wordpress vr网站电影网页设计尺寸
  • 做淘宝客新增网站推广怎样开一家公司
  • 企业网站有必要做吗?网站平均停留时间
  • 蘑菇街的网站建设凡科网站建设网页怎么建