Zxing中文乱码解决方法总结

尝试过很多方法  最后发现此方法解决的乱码最多.......

 

在百度搜索二维码图片

经过前2页的测试  除开一张图之外  其余都能扫描出结果 

如果大家有更好的解决方法 请联系我 谢谢

 

解决方法如下:

首先使用反射的方法判断扫描结果 

是不是ISO8859-1的编码格式

如果是    ISO8859-1  编码格式就将扫描结果转换成GB2312

如果不是ISO8859-1 编码就直接显示......希望大家补充   

我写了一个工具类

 

/**
	 * 中文乱码
	 * 
	 * 暂时解决大部分的中文乱码 但是还有部分的乱码无法解决 .
	 * 
	 * 如果您有好的解决方式 请联系我	  
	 * 我会很乐意向您请教 谢谢您
	 * 
	 * @return
	 */
	private String recode(String str) {
		String formart = "";

		try {
			boolean ISO = Charset.forName("ISO-8859-1").newEncoder()
					.canEncode(str);
			if (ISO) {
				formart = new String(str.getBytes("ISO-8859-1"), "GB2312");
				Log.i("1234      ISO8859-1", formart);
			} else {
				formart = str;
				Log.i("1234      stringExtra", str);
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return formart;
	}

 

将扫描结果传进这个方法中   会返回给你一个解析好的字符串

 

希望对您有用

资源下载地址:http://download.csdn.net/detail/aaawqqq/7281577

 

GitHub 加速计划 / zx / zxing
12
1
下载
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
最近提交(Master分支:4 个月前 )
50799640 Bumps [org.apache.maven.plugins:maven-release-plugin](https://github.com/apache/maven-release) from 3.1.1 to 3.2.0. - [Release notes](https://github.com/apache/maven-release/releases) - [Commits](https://github.com/apache/maven-release/compare/maven-release-3.1.1...maven-release-3.2.0) --- updated-dependencies: - dependency-name: org.apache.maven.plugins:maven-release-plugin dependency-version: 3.2.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 1 个月前
132ba33d Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 1 个月前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐