0 0

java做摄像头扫描二维码15

电脑摄像头扫描二维码并解码
程序是日本人写的那个二维码qrcode.zip包里面的jmf
错误:
Exception in thread "Thread-3" java.lang.IllegalArgumentException: Width (0) and height (0) cannot be <= 0
at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:999)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:312)
at jmf.J2SEImage.<init>(QRCodeDecoderJMFExample.java:93)
at jmf.QRCodeDecoderJMFExample.run(QRCodeDecoderJMFExample.java:56)
at java.lang.Thread.run(Thread.java:619)


源代码:
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.PixelGrabber;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.media.Buffer;
import javax.media.Processor;
import javax.media.control.FrameGrabbingControl;
import javax.media.format.VideoFormat;
import javax.media.util.BufferToImage;
import jp.sourceforge.qrcode.QRCodeDecoder;
import jp.sourceforge.qrcode.data.QRCodeImage;
import jp.sourceforge.qrcode.exception.DecodingFailedException;
import jp.sourceforge.qrcode.geom.Line;
import jp.sourceforge.qrcode.geom.Point;
import jp.sourceforge.qrcode.util.DebugCanvas;
public class QRCodeDecoderJMFExample implements Runnable {
Processor processor;
QRCodeDecoder decoder;
JMFCanvas canvas;
public QRCodeDecoderJMFExample(Processor processor) {
this.processor = processor;
}
public BufferedImage getDebugImage() {
return canvas.getImage();
}
public  void run() {
for (;;) {
        FrameGrabbingControl fgc = (FrameGrabbingControl) processor.getControl("javax.media.control.FrameGrabbingControl");
        Buffer buf = fgc.grabFrame();
        BufferToImage btoi = new BufferToImage((VideoFormat)buf.getFormat());
        Image img = btoi.createImage(buf);
        QRCodeDecoder decoder = new QRCodeDecoder();
        int width = processor.getVisualComponent().getWidth();
        int height = processor.getVisualComponent().getHeight();
        canvas = new JMFCanvas();
        QRCodeDecoder.setCanvas(canvas);
        try {
        J2SEImage decoderImage = new J2SEImage(img, width, height);
                        byte[] b=decoder.decode(decoderImage);
                        String decodedString;
                        if(b!=null)
            decodedString=new String(decoder.decode(decoderImage));
                        else
                            decodedString="";
        System.out.println("Result: "+ decodedString);
        File resultImage = new File("C:\\img\\TestQRCode.JPG");
        try {
        ImageIO.write(canvas.getImage(), "png", resultImage);
        } catch (IOException e) {
        System.out.println("失败");
        System.out.println(e.getMessage());
        }
        } catch (DecodingFailedException e) {
//         System.out.println("Error: "+e.getMessage());
                    System.out.println("Error: 解码失败");
        } catch (IllegalStateException e) {
//         System.out.println("Error: "+e.getMessage());
                    System.out.println("Error: 状态错误");
        }
        try {
        Thread.sleep(500);
        } catch (InterruptedException e) {
        System.out.println(e.getMessage());
        }
}
}
}
class J2SEImage implements QRCodeImage {
BufferedImage image;
int[] pixels;
PixelGrabber pg;
public J2SEImage(Image img, int width, int height) {
image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = image.createGraphics();
g2.drawImage(img, null, null);
}

public int getWidth() {
return image.getWidth();
}

public int getHeight() {
return image.getHeight();
}

public int getPixel(int x, int y) {
return image.getRGB(x, y);
}
}
class JMFCanvas extends Canvas implements DebugCanvas {
BufferedImage image;
public void paint(Graphics g){
if (image != null)
g.drawImage(image, 0, 0, java.awt.Color.WHITE, null);
}
public  void println(String string){
//System.out.println(string);
}
public  void drawMatrix(boolean[][] matrix) {
if (image == null) {
image = new BufferedImage(matrix.length, matrix[0].length, BufferedImage.TYPE_INT_ARGB);
setSize(matrix.length, matrix[0].length);
}
Graphics2D g2d = image.createGraphics();
g2d.setColor(java.awt.Color.WHITE);
int width = getWidth();
for (int x = 0; x < matrix.length; x++) {
g2d.drawLine(x, 0, x, width);
}
g2d.setColor(java.awt.Color.BLACK);
for (int x = 0; x < matrix.length; x++) {
for (int y = 0; y < matrix[0].length; y++) {
if (matrix[x][y] == true)
g2d.drawLine(x, y, x, y);
}
}
repaint();
}
public  void drawLine(Line line, int color){
Graphics2D g2d = image.createGraphics();
g2d.setColor(new Color(color));
g2d.drawLine(line.getP1().getX(), line.getP1().getY(),
line.getP2().getX(), line.getP2().getY());
repaint();
}
public  void drawLines(Line[] lines, int color){
Graphics2D g2d = image.createGraphics();
g2d.setColor(new Color(color));
for (int i = 0; i < lines.length; i++) {
g2d.drawLine(lines[i].getP1().getX(), lines[i].getP1().getY(),
lines[i].getP2().getX(), lines[i].getP2().getY());
}
repaint();
}
public  void drawPolygon(Point[] points, int color){
Graphics2D g2d = image.createGraphics();
g2d.setColor(new Color(color));
int numPoints = points.length;
int[] polygonX = new int[numPoints];
int[] polygonY = new int[numPoints];
for (int i = 0; i < numPoints; i++) {
polygonX[i] = points[i].getX();
polygonY[i] = points[i].getY();
}
g2d.drawPolygon(polygonX, polygonY, numPoints);
repaint();
}
public  void drawPoints(Point[] points, int color){
Graphics2D g2d = image.createGraphics();
g2d.setColor(new Color(color));
for (int i = 0; i < points.length; i++)
g2d.drawLine(points[i].getX(), points[i].getY(),points[i].getX(), points[i].getY());
repaint();

}
public  void drawPoint(Point point, int color){
Graphics2D g2d = image.createGraphics();
g2d.setColor(new Color(color));
g2d.drawLine(point.getX(), point.getY(),point.getX(), point.getY());
repaint();

}
public  void drawCross(Point point, int color){
int x = point.getX();
int y = point.getY();

Line[] lines = {
new Line(x - 5, y-1, x + 5, y-1),new Line(x-1, y - 5, x-1 ,y + 5),
new Line(x - 5, y+1, x + 5, y+1),new Line(x+1, y - 5, x+1 ,y + 5),
new Line(x - 5, y, x + 5, y),new Line(x, y - 5, x ,y + 5)
};
drawLines(lines, color);
}
public BufferedImage getImage() {
return image;
}
public void setImage(BufferedImage image) {
this.image = image;
}
}


谁有能用的程序啊,发一个吧,465955146@qq.com
2012年3月22日 11:59
  • jmf.zip (8.7 KB)
  • 下载次数: 83

1个答案 按时间排序 按投票排序

0 0

为什么没有大神来呢

2012年3月27日 18:04

相关推荐

    java摄像头读取二维码(整个java项目)

    Java摄像头读取二维码是一项在物联网和移动应用中常见的技术,它允许通过摄像头捕获图像,然后解析其中的二维码信息。本项目提供了一个完整的Java解决方案,包括了必要的代码和配置,以便开发者可以快速理解和实现...

    用电脑摄像头扫描二维码

    综上所述,实现“用电脑摄像头扫描二维码”的Java小程序涉及到图像处理、二维码解码、摄像头访问、事件处理和多线程等多个方面的知识。通过掌握这些技术,我们可以开发出高效、易用的二维码扫描工具,进一步拓展电脑...

    java实现电脑端扫描二维码

    在Java中实现电脑端扫描二维码的过程涉及到多个步骤,包括前端的图像捕获、后端的图像处理和解码。以下是对这些步骤的详细说明: 1. **前端图像捕获**: - 前端使用JavaScript来调用电脑摄像头进行拍照。这通常...

    Android webview调用摄像头扫描二维码

    以上就是关于“Android Webview调用摄像头扫描二维码”的详细实现步骤和相关知识点。这个过程展示了如何在Android应用中融合Webview和原生功能,以实现更丰富的交互体验。通过学习和实践,开发者可以更好地掌握混合...

    Android使用WebView调用H5完成摄像头扫描二维码

    这篇教程将详细介绍如何在Android中利用WebView来调用H5页面,从而实现摄像头扫描二维码的功能。 首先,我们需要理解WebView的基本用法。WebView是Android SDK提供的一种控件,它可以加载本地或者远程的HTML、CSS和...

    Html5调用摄像头读取二维码(全部源码)

    在这个"Html5调用摄像头读取二维码(全部源码)"项目中,我们主要探讨的是如何利用HTML5的 getUserMedia API 和二维码识别库来实现在网页上直接通过摄像头扫描二维码的功能。 1. **getUserMedia API**: 这是...

    扫描二维码下载 JAVA实现20190403

    本文将深入探讨如何使用JAVA实现扫描二维码自动下载对应客户端类型的APP功能。 首先,我们需要理解二维码的基本原理。二维码(Quick Response Code)是一种二维条形码,存储的数据可以是网址、文字、图片、联系人...

    Android APP使用WebView调用H5页面完成摄像头扫描二维码软件源码.rar

    在Android应用开发中,WebView是一个非常重要的组件,...以上就是Android APP使用WebView调用H5页面完成摄像头扫描二维码的关键技术点。通过这个示例,开发者可以学习到如何结合原生功能与H5页面,提升APP的用户体验。

    java使用电脑摄像头识别二维码

    Java 使用电脑摄像头识别二维码 Java 使用电脑摄像头识别二维码是指利用 Java 语言在电脑上使用摄像头获取图像,并从图像中解析出二维码信息的技术。本技术主要涉及到两个基本功能:从摄像头获取图像和根据图片解析...

    Java程序批量生成二维码EPS、CSV、PDF矢量图和各种格式二维码

    面向开发人员,和经常接触使用各种二维码的人,这个工具能帮助开发二维码的人员生成各种格式二维码,包括png,jpg,bpm,gif,SVG(矢量),EPS(矢量),PDF(矢量),并且能够调用电脑的摄像头扫描二维码,将码...

    JAVA整合HTML5实现扫描二维码功能项目源码

    项目使用环境以及工具: Eclipse,JDK1.7,struts2,HTML5,Jquery,QRCode HTML5技术支持WebApp在手机上拍照,显示在页面上并上传到...这是手机微博应用中常见的功能,当然你也可以在其它类型应用中适当使用此技术。

    Android 扫描二维码,类似微信的不断放大扫描效果, 识别率高。

    这里,我们关注的核心技术点包括扫描二维码、放大功能、创建二维码以及提高识别率。 首先,扫描二维码是整个功能的基础。Android中常用的库有Zxing(ZXing,全称为“Zebra Crossing”),这是一个开源的二维码和...

    delphixe7 android二维码扫描ZXing

    【标题】"Delphi XE7 Android二维码扫描ZXing"涉及的是在Delphi XE7环境下,使用ZXing库开发Android应用,实现二维码和条形码的扫描功能。ZXing,全称为“Zebra Crossing”,是一款开源的多平台条码读取库,支持多种...

    实现扫描二维码功能项目源码JAVA整合HTML5.zip

    在本项目中,我们主要探讨如何使用Java与HTML5技术实现一个扫描二维码的功能。这个功能在现代移动应用和网页开发中十分常见,它允许用户通过摄像头快速读取和解析二维码中的信息,例如网址、文本、联系人信息等。...

    Java窗体程序批量生成二维码EPS、CSV、PDF矢量图和各种格式二维码图片

    面向开发人员,和经常接触使用各种二维码的人,这个工具能帮助开发二维码的人员生成各种格式二维码,包括png,jpg,bpm,gif,SVG(矢量),EPS(矢量),PDF(矢量),并且能够调用电脑的摄像头扫描二维码,将码...

    Android使用webview调用原生摄像头并扫描二维码

    在Android开发中,有时我们需要在Webview中集成一些原生的功能,比如调用摄像头扫描二维码。这个场景在很多移动应用中都有所应用,比如在线购物、社交媒体等。下面将详细介绍如何实现这一功能。 首先,我们需要了解...

    opencv+zbar实现摄像头二维码识别

    接着,使用ZBar的ImageScanner类扫描图像中的二维码。这个过程会返回一个结果集,包含了识别到的所有二维码的信息。 识别到的二维码数据通常是以Unicode编码的形式返回,为了将这些数据转换为可读的中文字符串,你...

    基于Java的二维码识别系统.pdf

    二维码的识别则是通过摄像头扫描到的图像,经过位置探测图形定位后,通过解码流程获取二维码中存储的信息。 #### 音频处理技术在中波转播台的应用 在音频处理方面,脉宽调制正反馈技术对于提高声音信号的可靠性...

    基于Java语言的飞网二维码生成与识别工具设计源码

    该工具为Java语言编写的飞网二维码解决方案源码,包含27个文件...此外,它还支持利用电脑摄像头扫描二维码并识别内容,以及从剪切板中识别二维码,并将生成的二维码复制到剪切板中,适用于二维码生成和识别的多种场景。

    实现扫描二维码并且解析二维码

    本篇文章将详细介绍如何实现扫描二维码并解析其内容,同时涵盖自动变焦和自定义照相机的相关技术。 一、二维码扫描与解析 1. **二维码基础**:二维码是一种二维条形码,能够存储更多的信息,包括文字、数字、网址...

Global site tag (gtag.js) - Google Analytics