ImageVerifierCode 换一换
格式:DOCX , 页数:12 ,大小:17.04KB ,
资源ID:5978986      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/5978986.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java使用Zxing包制作二维码.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java使用Zxing包制作二维码.docx

1、Java使用Zxing包制作二维码域名 长度 后缀 删除日期 删除类型 33d.cc 3 cc 2012/9/4 Delete 今天朋友问我一个二维码的东西,说实话我重来也没接触过,于是上网找了一下,和朋友分享一下.用qrcode.jar也能做,但是一看小日本的,于是马上闪过,听所zxing挺好用的,于是就去google下了架包用了这个感觉确实简单,重XX找到写完一个例子只用了,10来分钟. /www.hake.ccZxing是Google提供的关于条码(一维码、二维码)的解析工具,提供了二维码的生成与解析的方法,现在我简单介绍一下使用Java利用Zxing生成与解析二维码1、二维码的生成1.

2、1 将core.jar 包加入到classpath下。 1.2 二维码的生成需要借助MatrixToImageWriter类,该类是由Google提供的,可以将该类拷贝到源码中,这里我将该类的源码贴上,可以直接使用。java view plaincopyprint?import mon.BitMatrix; import javax.imageio.ImageIO; import java.io.File; import java.io.OutputStream; import java.io.IOException; import java.awt.image.BufferedImage;

3、public final class MatrixToImageWriter private static final int BLACK = 0xFF000000; private static final int WHITE = 0xFFFFFFFF; private MatrixToImageWriter() public static BufferedImage toBufferedImage(BitMatrix matrix) int width = matrix.getWidth(); int height = matrix.getHeight(); BufferedImage i

4、mage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x width; x+) for (int y = 0; y height; y+) image.setRGB(x, y, matrix.get(x, y) ? BLACK : WHITE); return image; public static void writeToFile(BitMatrix matrix, String format, File file) throws IOException BufferedIm

5、age image = toBufferedImage(matrix); if (!ImageIO.write(image, format, file) throw new IOException(Could not write an image of format + format + to + file); public static void writeToStream(BitMatrix matrix, String format, OutputStream stream) throws IOException BufferedImage image = toBufferedImage

6、(matrix); if (!ImageIO.write(image, format, stream) throw new IOException(Could not write an image of format + format); import mon.BitMatrix; import javax.imageio.ImageIO; import java.io.File; import java.io.OutputStream; import java.io.IOException; import java.awt.image.BufferedImage; public final

7、class MatrixToImageWriter private static final int BLACK = 0xFF000000; private static final int WHITE = 0xFFFFFFFF; private MatrixToImageWriter() public static BufferedImage toBufferedImage(BitMatrix matrix) int width = matrix.getWidth(); int height = matrix.getHeight(); BufferedImage image = new Bu

8、fferedImage(width, height, BufferedImage.TYPE_INT_RGB); for (int x = 0; x width; x+) for (int y = 0; y sourceWidth | top + height sourceHeight) throw new IllegalArgumentException(Crop rectangle does not fit within image data.); for (int y = top; y top + height; y+) for (int x = left; x left + width;

9、 x+) if (image.getRGB(x, y) & 0xFF000000) = 0) image.setRGB(x, y, 0xFFFFFFFF); / = white this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY); this.image.getGraphics().drawImage(image, 0, 0, null); this.left = left; this.top = top; Override public byte getRow(int y

10、, byte row) if (y = getHeight() throw new IllegalArgumentException(Requested row is outside the image: + y); int width = getWidth(); if (row = null | row.length sourceWidth | top + height sourceHeight) throw new IllegalArgumentException(Crop rectangle does not fit within image data.); for (int y = t

11、op; y top + height; y+) for (int x = left; x left + width; x+) if (image.getRGB(x, y) & 0xFF000000) = 0) image.setRGB(x, y, 0xFFFFFFFF); / = white this.image = new BufferedImage(sourceWidth, sourceHeight, BufferedImage.TYPE_BYTE_GRAY); this.image.getGraphics().drawImage(image, 0, 0, null); this.left

12、 = left; this.top = top; Overridepublic byte getRow(int y, byte row) if (y = getHeight() throw new IllegalArgumentException(Requested row is outside the image: + y); int width = getWidth(); if (row = null | row.length width) row = new bytewidth; image.getRaster().getDataElements(left, top + y, width

13、, 1, row); return row; Overridepublic byte getMatrix() int width = getWidth(); int height = getHeight(); int area = width * height; byte matrix = new bytearea; image.getRaster().getDataElements(left, top, width, height, matrix); return matrix; Overridepublic boolean isCropSupported() return true; Ov

14、erridepublic LuminanceSource crop(int left, int top, int width, int height) return new BufferedImageLuminanceSource(image, this.left + left, this.top + top, width, height); Overridepublic boolean isRotateSupported() return true; Overridepublic LuminanceSource rotateCounterClockwise() int sourceWidth = image.getWidth(); int sourceHeight = image.getHeight(); AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth); BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedIm

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1