Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
874c133b
mica
项目概览
mica
/
mica
通知
10
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
874c133b
编写于
9月 22, 2021
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
mica-qrcode 代码完善。
上级
949a8b32
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
105 addition
and
3 deletion
+105
-3
mica-qrcode/src/main/java/net/dreamlu/mica/qrcode/QrCode.java
...-qrcode/src/main/java/net/dreamlu/mica/qrcode/QrCode.java
+105
-3
未找到文件。
mica-qrcode/src/main/java/net/dreamlu/mica/qrcode/QrCode.java
浏览文件 @
874c133b
...
...
@@ -40,6 +40,7 @@ import java.net.URL;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.util.Hashtable
;
import
java.util.Map
;
/**
* QRCode 读写,基于 nutz-plugins-qrcode 调整,简化使用
...
...
@@ -403,10 +404,9 @@ public final class QrCode {
* @return QRCode 的图像对象
*/
public
BufferedImage
toImage
()
{
String
text
=
new
String
(
content
.
getBytes
(
this
.
encode
),
this
.
encode
);
BitMatrix
matrix
;
try
{
matrix
=
new
QRCodeWriter
().
encode
(
tex
t
,
matrix
=
new
QRCodeWriter
().
encode
(
conten
t
,
BarcodeFormat
.
QR_CODE
,
this
.
size
,
this
.
size
,
...
...
@@ -470,10 +470,63 @@ public final class QrCode {
* @return QRCode 中的内容
*/
public
static
String
read
(
BufferedImage
qrCodeImage
)
{
return
read
(
qrCodeImage
,
(
Map
<
DecodeHintType
,?>)
null
);
}
/**
* 从指定的 QRCode 图片文件中解析出其内容。
*
* @param qrCodeFile QRCode 文件
* @return QRCode 中的内容
*/
public
static
String
read
(
String
qrCodeFile
,
Charset
encode
)
{
return
read
(
ImageUtil
.
read
(
qrCodeFile
),
encode
);
}
/**
* 从指定的 QRCode 图片文件中解析出其内容。
*
* @param qrCodeFile QRCode 图片文件
* @return QRCode 中的内容
*/
public
static
String
read
(
File
qrCodeFile
,
Charset
encode
)
{
return
read
(
ImageUtil
.
read
(
qrCodeFile
),
encode
);
}
/**
* 从指定的 QRCode 图片链接中解析出其内容。
*
* @param qrCodeUrl QRCode 图片链接
* @return QRCode 中的内容
*/
public
static
String
read
(
URL
qrCodeUrl
,
Charset
encode
)
{
return
read
(
ImageUtil
.
read
(
qrCodeUrl
),
encode
);
}
/**
* 从指定的 QRCode 图像对象中解析出其内容。
*
* @param qrCodeImage QRCode 图像对象
* @return QRCode 中的内容
*/
public
static
String
read
(
BufferedImage
qrCodeImage
,
Charset
encode
)
{
Map
<
DecodeHintType
,
Object
>
hints
=
new
Hashtable
<>();
hints
.
put
(
DecodeHintType
.
CHARACTER_SET
,
encode
);
return
read
(
qrCodeImage
,
hints
);
}
/**
* 从指定的 QRCode 图像对象中解析出其内容。
*
* @param qrCodeImage QRCode 图像对象
* @param hints hints
* @return QRCode 中的内容
*/
public
static
String
read
(
BufferedImage
qrCodeImage
,
Map
<
DecodeHintType
,?>
hints
)
{
LuminanceSource
source
=
new
BufferedImageLuminanceSource
(
qrCodeImage
);
BinaryBitmap
bitmap
=
new
BinaryBitmap
(
new
HybridBinarizer
(
source
));
try
{
Result
result
=
new
QRCodeReader
().
decode
(
bitmap
);
Result
result
=
new
QRCodeReader
().
decode
(
bitmap
,
hints
);
return
result
.
getText
();
}
catch
(
NotFoundException
|
ChecksumException
|
FormatException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
...
...
@@ -482,6 +535,55 @@ public final class QrCode {
}
}
/**
* 从指定的 QRCode 图片文件中解析出其内容。
*
* @param qrCodeFile QRCode 文件
* @return QRCode 中的内容
*/
public
static
byte
[]
readRawBytes
(
String
qrCodeFile
)
{
return
readRawBytes
(
ImageUtil
.
read
(
qrCodeFile
));
}
/**
* 从指定的 QRCode 图片文件中解析出其内容。
*
* @param qrCodeFile QRCode 图片文件
* @return QRCode 中的内容
*/
public
static
byte
[]
readRawBytes
(
File
qrCodeFile
)
{
return
readRawBytes
(
ImageUtil
.
read
(
qrCodeFile
));
}
/**
* 从指定的 QRCode 图片链接中解析出其内容。
*
* @param qrCodeUrl QRCode 图片链接
* @return QRCode 中的内容
*/
public
static
byte
[]
readRawBytes
(
URL
qrCodeUrl
)
{
return
readRawBytes
(
ImageUtil
.
read
(
qrCodeUrl
));
}
/**
* 从指定的 QRCode 图像对象中解析出其内容。
*
* @param qrCodeImage QRCode 图像对象
* @return QRCode 中的内容
*/
public
static
byte
[]
readRawBytes
(
BufferedImage
qrCodeImage
)
{
LuminanceSource
source
=
new
BufferedImageLuminanceSource
(
qrCodeImage
);
BinaryBitmap
bitmap
=
new
BinaryBitmap
(
new
HybridBinarizer
(
source
));
try
{
Result
result
=
new
QRCodeReader
().
decode
(
bitmap
);
return
result
.
getRawBytes
();
}
catch
(
NotFoundException
|
ChecksumException
|
FormatException
e
)
{
throw
Exceptions
.
unchecked
(
e
);
}
finally
{
qrCodeImage
.
getGraphics
().
dispose
();
}
}
private
static
void
addLogo
(
BufferedImage
qrCodeImage
,
BufferedImage
logoImage
,
QrCode
qrCode
)
{
int
baseWidth
=
qrCodeImage
.
getWidth
();
int
baseHeight
=
qrCodeImage
.
getHeight
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录