function gen( content )
%% 加载jar与需要用到是JAVA类
Jpath=[pwd '\zxing17'];
javaaddpath(Jpath)
import java.util.Hashtable;
import java.lang.String
import com.google.zxing.*
%% 定义
b=java.util.HashMap;
b.put(EncodeHintType.CHARACTER_SET, 'UTF-8'); %中文定义
%% 转换
content = java.lang.String(content);
hints=Hashtable;
hints.put(EncodeHintType.CHARACTER_SET, 'UTF-8');
%% 调用JAVA完成二维码制作
writer = com.google.zxing.MultiFormatWriter();
bitmtx = writer.encode(content,com.google.zxing.BarcodeFormat.QR_CODE,400, 400,hints);
mtx = char(bitmtx);
mtx(mtx==10) = [];
mtx = reshape(mtx(1:2:end), 400, 400)';
mtx(mtx~='X') = 1;
mtx(mtx=='X') = 0;
mtx = double(mtx);
imshow(mtx);
end
|