久久天天躁狠狠躁夜夜免费观看,精品国产粉嫩内射白浆内射双马尾,久久国产欧美日韩精品,久久久久久性高,激情欧美成人久久综合

Java 解析二維碼,google.ZXing 講解

JSON 2016-08-22 17:14:14 36875

Zxing  庫的主要部分支持以下幾個(gè)功能:核心代碼的使用、適用于J2SE客戶端的版本、適用于 Android  客戶端的版本(即BarcodeScanner)、 Android  的集成(通過Intent支持和BarcodeScanner的集成)。

本站 Demo  http://suancuo.cn/deqr.html

Jar包請?jiān)诟郊螺d。

下面直接上代碼。

代碼一:

package com.sojson.code.manager;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.sojson.common.utils.StringUtils;

/**
 * 
 * 開發(fā)公司:itboy.net<br/>
 * 版權(quán):itboy.net<br/>
 * <p>
 * 
 * 編碼解碼 Manager
 * 
 * <p>
 * 
 * 區(qū)分 責(zé)任人 日期    說明<br/>
 * 創(chuàng)建 周柏成 2015年11月7日  <br/>
 * <p>
 * *******
 * <p>
 * @author zhou-baicheng
 * @email  i@itboy.net
 * @version 1.0,2015年11月7日 <br/>
 * 
 */
public class CodeManager {

	/**
	 * 通過Url地址或者圖片解碼
	 * 
	 * @param request
	 * @param url
	 * @return
	 */
	public static Map<String, Object> decode(
			MultipartHttpServletRequest request, String url) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		InputStream inputStream = null;
		if (StringUtils.isNotBlank(url)) {
			try {
				URL exurl = new URL(url);
				HttpURLConnection httpConn = (HttpURLConnection) exurl
						.openConnection();
				httpConn.connect();
				inputStream = httpConn.getInputStream();
			} catch (Exception e) {
				resultMap.put("status", 500);
				resultMap.put("message", "解碼失敗,Url地址有誤沒有獲取到文件");
				return resultMap;
			}

		} else {
			Map<String, MultipartFile> fileMap = request.getFileMap();
			try {
				for (String fileName : fileMap.keySet()) {
					MultipartFile mutFile = fileMap.get(fileName);
					inputStream = mutFile.getInputStream();
				}
			} catch (Exception e) {
				resultMap.put("status", 500);
				resultMap.put("message", "解碼失敗:" + e.getMessage());
			}
		}
		try {
			String code = MatrixUtil.decode(inputStream);
			resultMap.put("text", code);
			resultMap.put("status", 200);
		} catch (Exception e) {
			resultMap.put("status", 500);
			resultMap.put("message", "解碼失敗");
		}
		return resultMap;
	}
}

代碼二:

package com.sojson.code.manager;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.InputStream;
import java.util.Hashtable;

import javax.imageio.ImageIO;

import com.google.zxing.BinaryBitmap;
import com.google.zxing.DecodeHintType;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;

/**
 * 使用ZXing2.3,生成條碼的輔助類??梢跃幋a、解碼。編碼使用code包,解碼需要javase包。
 * 
 */
public final class MatrixUtil {

	private static final String CHARSET = "utf-8";

	/**
	 * 禁止生成實(shí)例,生成實(shí)例也沒有意義。
	 */
	private MatrixUtil() {
	}


	/**
	 * 解碼,需要javase包。
	 * 文件方式解碼
	 * @param file
	 * @return
	 */
	public static String decode(File file) {

		BufferedImage image;
		try {
			if (file == null || file.exists() == false) {
				throw new Exception(" File not found:" + file.getPath());
			}

			image = ImageIO.read(file);

			LuminanceSource source = new BufferedImageLuminanceSource(image);
			BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

			Result result;

			// 解碼設(shè)置編碼方式為:utf-8,
			Hashtable<DecodeHintType,String> hints = new Hashtable<DecodeHintType,String>();
			hints.put(DecodeHintType.CHARACTER_SET, CHARSET);

			result = new MultiFormatReader().decode(bitmap, hints);

			return result.getText();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 流方式解碼
	 * @param input
	 * @return
	 */
	public static String decode(InputStream input) {
		
		BufferedImage image;
		try {
			if (input == null ) {
				throw new Exception(" input is null");
			}
			
			image = ImageIO.read(input);
			
			LuminanceSource source = new BufferedImageLuminanceSource(image);
			BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
			
			Result result;
			
			// 解碼設(shè)置編碼方式為:utf-8,
			Hashtable<DecodeHintType,String> hints = new Hashtable<DecodeHintType,String>();
			hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
			
			result = new MultiFormatReader().decode(bitmap, hints);
			
			return result.getText();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}

Java Jar包下載請看附件。


版權(quán)所屬:SO JSON在線解析

原文地址:http://suancuo.cn/blog/92.html

轉(zhuǎn)載時(shí)必須以鏈接形式注明原始出處及本聲明。


附件下載:

備注:點(diǎn)擊文件名下載,附件源來自云端,只能在本站下載。復(fù)制下載鏈接無效。

本文主題:

如果本文對你有幫助,那么請你贊助我,讓我更有激情的寫下去,幫助更多的人。

關(guān)于作者
一個(gè)低調(diào)而悶騷的男人。
相關(guān)文章
使用zxing解析二維碼拋出com.google.zxing.NotFoundException 解決方案
二維碼解碼原理:從信息編碼到解碼的奧秘
二維碼解碼原理:從信息編碼到解碼的奧秘
微信支付功能--PC端生成二維碼,實(shí)現(xiàn)掃描支付功能
json 解析與生成工具類 ,JSON操作講解(附件)
Java 完美解析.plist & 生成plist ,Android 解析.plist
阿里云DNS 解析講解,SEO配置搜索引擎線路解析
Java 解析JSON,JSON-LIB jar包下載和使用。
Java生成驗(yàn)證合集()GIF版,Java生成動(dòng)圖驗(yàn)證
json解析的幾種方式
最新文章
計(jì)算機(jī)網(wǎng)絡(luò)的相關(guān)內(nèi)容 759
SOJSON V6 JavaScript 解密技巧與分析 6127
微信客服人工電話95068:如何快速解封微信賬號(2025最新指南) 12229
Java Http請求,HttpURLConnection HTTP請求丟失頭信息,Head信息丟失解決方案 5097
實(shí)用API合集分享:教你輕松獲取IP地址的API合集 8880
Linux I/O重定向 6723
Ruby 循環(huán) - while、for、until、break、redo 和 retry 3996
Node.js:全局對象 3614
如何使用終端檢查Linux上的內(nèi)存使用情況 3779
JavaScript對象詳細(xì)剖析 3280
最熱文章
免費(fèi)天氣API,天氣JSON API,不限次數(shù)獲取十五天的天氣預(yù)報(bào) 746874
最新MyEclipse8.5注冊碼,有效期到2020年 (已經(jīng)更新) 703436
蘋果電腦Mac怎么恢復(fù)出廠系統(tǒng)?蘋果系統(tǒng)怎么重裝系統(tǒng)? 678486
Jackson 時(shí)間格式化,時(shí)間注解 @JsonFormat 用法、時(shí)差問題說明 561963
我為什么要選擇RabbitMQ ,RabbitMQ簡介,各種MQ選型對比 511842
Elasticsearch教程(四) elasticsearch head 插件安裝和使用 483742
Jackson 美化輸出JSON,優(yōu)雅的輸出JSON數(shù)據(jù),格式化輸出JSON數(shù)據(jù)... ... 299614
Java 信任所有SSL證書,HTTPS請求拋錯(cuò),忽略證書請求完美解決 246723
Elasticsearch教程(一),全程直播(小白級別) 232162
227553
支付掃碼

所有贊助/開支都講公開明細(xì),用于網(wǎng)站維護(hù):贊助名單查看

查看我的收藏

正在加載... ...