- 浏览: 72420 次
- 性别:
- 来自: 富安
最新评论
-
simpledev:
...
10步让你成为更优秀的程序员 -
bavnnsym:
像三楼说的那样,,是可以的,,我之前也碰到这个问题,,也是在d ...
IE6层不能遮挡住下拉框问题解决 -
suko:
yukaizhao 写道一句话的事情,就是创建一个和层一样大小 ...
IE6层不能遮挡住下拉框问题解决 -
yukaizhao:
一句话的事情,就是创建一个和层一样大小,一样位置的iframe ...
IE6层不能遮挡住下拉框问题解决 -
kaipingk:
andyyehoo 写道可以参考一下Struts2的日历控件的 ...
IE6层不能遮挡住下拉框问题解决
本例我是应用google的二维码工具包来做的,附近提供jar包下载。下面是完整代码,经过测试的。
package test; import java.awt.BasicStroke; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Shape; import java.awt.geom.RoundRectangle2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.OutputStream; import java.util.Hashtable; import java.util.Random; import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat; import com.google.zxing.BinaryBitmap; import com.google.zxing.DecodeHintType; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatReader; import com.google.zxing.MultiFormatWriter; import com.google.zxing.Result; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; public class QRCodeUtil { private static final String CHARSET = "utf-8"; private static final String FORMAT_NAME = "JPG"; // 二维码尺寸 private static final int QRCODE_SIZE = 300; // LOGO宽度 private static final int WIDTH = 60; // LOGO高度 private static final int HEIGHT = 60; private static BufferedImage createImage(String content, String imgPath, boolean needCompress) throws Exception { Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>(); hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); hints.put(EncodeHintType.CHARACTER_SET, CHARSET); hints.put(EncodeHintType.MARGIN, 1); BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints); int width = bitMatrix.getWidth(); int height = bitMatrix.getHeight(); BufferedImage image = 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, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); } } if (imgPath == null || "".equals(imgPath)) { return image; } // 插入图片 QRCodeUtil.insertImage(image, imgPath, needCompress); return image; } /** * 插入LOGO * * @param source * 二维码图片 * @param imgPath * LOGO图片地址 * @param needCompress * 是否压缩 * @throws Exception */ private static void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception { File file = new File(imgPath); if (!file.exists()) { System.err.println(""+imgPath+" 该文件不存在!"); return; } Image src = ImageIO.read(new File(imgPath)); int width = src.getWidth(null); int height = src.getHeight(null); if (needCompress) { // 压缩LOGO if (width > WIDTH) { width = WIDTH; } if (height > HEIGHT) { height = HEIGHT; } Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(image, 0, 0, null); // 绘制缩小后的图 g.dispose(); src = image; } // 插入LOGO Graphics2D graph = source.createGraphics(); int x = (QRCODE_SIZE - width) / 2; int y = (QRCODE_SIZE - height) / 2; graph.drawImage(src, x, y, width, height, null); Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); graph.setStroke(new BasicStroke(3f)); graph.draw(shape); graph.dispose(); } /** * 生成二维码(内嵌LOGO) * * @param content * 内容 * @param imgPath * LOGO地址 * @param destPath * 存放目录 * @param needCompress * 是否压缩LOGO * @throws Exception */ public static void encode(String content, String imgPath, String destPath, boolean needCompress) throws Exception { BufferedImage image = QRCodeUtil.createImage(content, imgPath, needCompress); mkdirs(destPath); String file = new Random().nextInt(99999999)+".jpg"; ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file)); } /** * 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常) * @author lanyuan * Email: mmm333zzz520@163.com * @date 2013-12-11 上午10:16:36 * @param destPath 存放目录 */ public static void mkdirs(String destPath) { File file =new File(destPath); //当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常) if (!file.exists() && !file.isDirectory()) { file.mkdirs(); } } /** * 生成二维码(内嵌LOGO) * * @param content * 内容 * @param imgPath * LOGO地址 * @param destPath * 存储地址 * @throws Exception */ public static void encode(String content, String imgPath, String destPath) throws Exception { QRCodeUtil.encode(content, imgPath, destPath, false); } /** * 生成二维码 * * @param content * 内容 * @param destPath * 存储地址 * @param needCompress * 是否压缩LOGO * @throws Exception */ public static void encode(String content, String destPath, boolean needCompress) throws Exception { QRCodeUtil.encode(content, null, destPath, needCompress); } /** * 生成二维码 * * @param content * 内容 * @param destPath * 存储地址 * @throws Exception */ public static void encode(String content, String destPath) throws Exception { QRCodeUtil.encode(content, null, destPath, false); } /** * 生成二维码(内嵌LOGO) * * @param content * 内容 * @param imgPath * LOGO地址 * @param output * 输出流 * @param needCompress * 是否压缩LOGO * @throws Exception */ public static void encode(String content, String imgPath, OutputStream output, boolean needCompress) throws Exception { BufferedImage image = QRCodeUtil.createImage(content, imgPath, needCompress); ImageIO.write(image, FORMAT_NAME, output); } /** * 生成二维码 * * @param content * 内容 * @param output * 输出流 * @throws Exception */ public static void encode(String content, OutputStream output) throws Exception { QRCodeUtil.encode(content, null, output, false); } /** * 解析二维码 * * @param file * 二维码图片 * @return * @throws Exception */ public static String decode(File file) throws Exception { BufferedImage image; image = ImageIO.read(file); if (image == null) { return null; } BufferedImageLuminanceSource source = new BufferedImageLuminanceSource( image); BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); Result result; Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>(); hints.put(DecodeHintType.CHARACTER_SET, CHARSET); result = new MultiFormatReader().decode(bitmap, hints); String resultStr = result.getText(); return resultStr; } /** * 解析二维码 * * @param path * 二维码图片地址 * @return * @throws Exception */ public static String decode(String path) throws Exception { return QRCodeUtil.decode(new File(path)); } public static void main(String[] args) throws Exception { String text = "http://www.iteye.com"; //这里设置自定义网站url String logoPath = "d:\\zilv.jpg"; String destPath = "d:\\"; QRCodeUtil.encode(text, logoPath, destPath, true); } }
- core-3.1.0.jar (525.8 KB)
- 下载次数: 70
发表评论
-
Zookeeper+SolrCloud+Tomcat搭建分布式搜索应用
2016-03-10 15:39 968一.简介 SolrCloud是Solr4.0版本以后基于Sol ... -
ZooKeeper之java客户端访问-入门介绍
2016-03-04 10:47 736时间 2014-03-22 22:42:48 CS ... -
Solr 4.7.0部署及java调用solr
2016-02-25 15:19 503参考了以下2个网站 1.Solr在tomcat中的部署 htt ... -
HTTP请求如何带参
2015-11-10 22:21 702HTTP请求如何带参 转载自:http://www.cnbl ... -
MyBatis 配置sql语句输出
2015-09-29 15:37 12671.首先将ibatis log4j运行级别调到DEBUG可以在 ... -
自定义alert提示框
2015-09-23 16:48 601js和css写的自定义弹出框,可以自己修改颜色和布局,使得弹出 ... -
js判断手机系统类型
2015-09-21 13:52 563function checkOSType(){ ... -
net.sf.json.JSONObject 依赖的包
2015-03-01 20:55 6304依赖的包如下图: 主包为json-lib-2.3-jdk13. ... -
通过阻塞队列实现文件关键字检索功能
2015-01-26 13:57 619package com.queue; import ... -
Tomcat热部署
2014-11-25 09:50 482\conf\Catalina\localhost目录下新建xm ... -
合并多个excel文件到一个文件
2014-11-16 19:41 1221package com.ben.utils; imp ... -
Java实现FTP上传和下载
2014-08-14 15:04 843import java.io.ByteArrayInput ... -
使用正则表达式替换数字
2014-06-19 16:38 1130public static void main(Strin ... -
Java Webservice例子
2014-06-17 12:38 4921.webservice服务端代码,发布一个webservic ... -
Java基础知识汇总
2014-05-08 08:28 564一、关于main方法 1.main方法被定义为private, ... -
查看JDK源码
2014-05-07 22:54 481查看JDK源码: step1:打开MyEclipse选择Wi ... -
Java中取两个集合的并集、交集和差集
2014-04-23 16:58 112041.并集 也叫合集,即把两个集合的所有元素加在一起。 pu ... -
JXPathContext支持迷糊匹配
2014-03-12 15:40 1049看完例子就会了 public ... -
统计英文单词的数量
2014-03-12 10:18 702使用正则表达式来统计一段文字中的英文单词的数量 publi ... -
使用序列化方法实现list集合的深拷贝
2014-03-05 14:28 2957对于可序列化(实现Serializable接口)的对象,封装它 ...
相关推荐
java实现手机扫描二维码后网站跳转新页面,提供zxing和hutools的方式实现二维码的生成,动态刷新,验证跳转功能。
demo中含有jar包对应的maven地址,直接引入到pom中就可以使用了
使用Java生成带有Logo的二维码并能够实现扫描二维码跳转到指定地址的功能,源码打的jar包,直接导入就可使用,仅需改几个地址就可使用,零基础的福音!
主要介绍了java扫二维码自动跳转,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
java写的生成二维码的工具类,在javaweb开发过程中可能会用到,扫描二维码自动跳转到相应的网址。
主要介绍了Java实现的生成二维码统计扫描次数并转发到某个地址功能,可实现生成带统计功能的二维码,涉及java二维码的生成、参数传递、解析等相关操作技巧,需要的朋友可以参考下
文件中有用java已编写案例源码及所需jar包
二维码扫描通知,手机端扫描成功会调用此接口,发送session通知 手机端确认通知,手机端确认登录会调用此接口,发送确认登录通知 显示登录扫描二维码,使用base64编码显示二维码 二维码显示成功后,使用SSE方式开启...
先说一下实现了什么效果,app扫描php写的页面(也可以java网页,都一样的思路和步骤),扫描成功后跳转进入主页,光和你们这么说,肯定有人说了,没图说个jb,这就出来一个问题,很多人写博客,看这标题特别符合自己的...
java 生成二维码作为图片保存在自己设定的路线下,扫描后跳转到指定的URL界面
4. **签到签出**:用户通过扫描二维码完成签到和签出,系统自动更新座位状态。 5. **违规预警**:对于未按时签到或长时间未移动的用户,系统将发出违规预警。 6. **统计报告**:后台可以生成座位使用情况的统计报告...